Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Freek Van der Herten:
A package to log activity in a Laravel app
Jun 30, 2016 @ 09:46:17

In a new post to his site Freek Van der Herten shares information about a logging package they've developed for Laravel-based applications to make activity logging simpler throughout the app: laravel-activitylog.

n your apps there’s probably a lot going on. Users log in and out, they create, update and delete content, mails get sent and so on. For an administrator of an app these events provide useful insights. In almost every project we make at Spatie we log these events and show them in the admin-section of our site. [...] We made a new package called laravel-activitylog that makes logging activities in a Laravel app a cinch. In this blogpost I’d like to walk you through it.

He then goes through the basics of using the library, complete with code examples:

  • simple activity logging with messaging
  • providing the "acted on" object information
  • logging the information about who the actor was

There's also a section with details on automatic model logging, making it easier to see the changes on you data without having to log each one individually. He also shows you how to use multiple logs, providing a method to narrow down log records by type.

tagged: laravel application logging package example introduction model

Link: https://murze.be/2016/06/package-log-activity-laravel-app/

SitePoint Web Blog:
Heroku Alternative: Deploy Apps with Dokku on DigitalOcean
Jun 29, 2016 @ 10:28:54

On the SitePoint Web blog there's a new tutorial showing you how to deploy applications with Dokku on DigitalOcean in the same way that you might with Heroku.

When Heroku announced their (quite reasonable) new limits for free apps, I realized that I would have to find another source of hosting for all the small, low-traffic projects that I currently have running on Heroku. [...] Since I have such an unreasonable number of apps running on Heroku, I thought it was high time to try out Dokku. Dokku is a Heroku-like tool that allows you to deploy complex apps by simply pushing with Git.

They start with some of the differences between the Heroku setup and Dokku, mostly that Dokku uses Docker for the deployment and configuration. They then show you how to create a Dokku server on DigitalOcean: setting up the domain, making the application and deploying the app with a push and other datastore plugins.

tagged: heroku dokku digitalocean deploy application tutorial

Link: https://www.sitepoint.com/heroku-alternative-deploy-apps-dokku-digitalocean/

SitePoint PHP Blog:
Can Symfony Apps Be Fast on Vagrant? Let’s Check with SuluCMS!
Jun 28, 2016 @ 12:13:15

On the SitePoint PHP blog they've posted a new tutorial looking at the combination of Symfony applications (well, one specific one) and Vagrant to optimize it for the best performance possible.

In this short tutorial, we’ll set up Sulu, a new Symfony based CMS, and optimize it on a Vagrant environment. Why a dedicated tutorial handling this? Besides the fact that Sulu has a rather complex initialization procedure, it is based on Symfony which is infamously slow on virtual machines with shared filesystems, and thus needs additional optimizations post-install. The performance hacks in this post, while Sulu-specific, can be applied to any Symfony application to make it faster on Vagrant.

The rest of the post walks you through the steps to get the box set up and the Sulu application up and running:

  • New Box and Folder Sharing
  • App Type and Vagrant Boot (configuration)
  • Installing Sulu

Then they get into the speed improvements and "hacks" to make the overall system perform better. They make updates to the log/cache directory fetching, moving the "vendors" folder into the VM (non-synced) and enabling the APC caching on autoloading. The tutorial also includes a few helpful troubleshooting tips of things to check if a problem does happen to pop up.

tagged: tutorial symfony application vagrant sulucms performance

Link: https://www.sitepoint.com/symfony-on-vagrant-performance-hacks-sulucms-case-study/

Yappa Blog:
Symfony Components in a Legacy PHP application
Jun 21, 2016 @ 12:50:13

On the Yappa Tech blog Joeri Verdeyen has written up a post covering the integration of modern Symfony components into a legacy application with a relatively simple container setup and configuration.

Symfony Components are a set of decoupled and reusable PHP libraries. They are becoming the standard foundation on which the best PHP applications are built. You can use any of these components in any of your applications independently from the Symfony Framework.

[...] The purpose of this post is to roughly describe how to implement some of the Symfony Components. I've created a set of gists to get started. You should already know how Symfony Components work in the Symfony Framework.

He starts with an example Composer configuration pulling in some of the more popular Symfony packages (like VarDumper and FormBuilder). He then includes the code to bootstrap the container instance and the services.yml he's come up with to bootstrap and integrate all of the components. The tutorial ends with examples of putting some of these components to use in resolving controllers, using the FormBuilder, using the command line and outputting errors with the VarDumper.

tagged: symfony component legacy application tutorial container example

Link: http://tech.yappa.be/symfony-components-in-a-legacy-php-application

SitePoint PHP Blog:
Your Own Custom Annotations – More than Just Comments!
Jun 21, 2016 @ 11:04:14

The SitePoint PHP blog has posted a new tutorial from author Daniel Sipos showing you how you can use custom annotations in your Symfony-based application. You can also do annotation parsing outside of Symfony but that requires other external libraries to accomplish.

In this article, we are going to look at how we can create and use our own custom annotations in a Symfony 3 application. You know annotations right? They are the docblock metadata/configuration we see above classes, methods and properties. You’ve most likely seen them used to declare Controller routes (@Route()) and Doctrine ORM mappings (@ORM()), or even to control access to various classes and methods in packages like Rauth. But have you ever wondered how can you use them yourself?

[...] In this article we are going to build a small reusable bundle called WorkerBundle. [...] We’re going to develop a small concept that allows the definition of various Worker types which “operate” at various speeds and which can then be used by anyone in the application. The actual worker operations are outside the scope of this post, since we are focusing on setting up the system to manage them (and discover them via annotations).

He then gets into the code, creating the WorkerInterface the workers will implement and a sample worker class with an annotation describing it. Next up he creates the WorkerManager to create and get the current set of workers. Then comes the discovery process and the creation of a simple class that looks through files and finds those with the @Worker annotation and makes them available as a worker instance. Finally he "wires it all together" in the services configuration and shows an example of a basic worker instance and using it by calling its work method.

tagged: custom annotations worker example symfony application tutorial

Link: https://www.sitepoint.com/your-own-custom-annotations/

SitePoint PHP Blog:
Hacking the Fitbit – Emulating a Pager for Twitter DMs!
Jun 17, 2016 @ 10:27:57

The SitePoint PHP blog has a tutorial they've posted from Christopher Pitt showing you how to hack your Fitbit into a pager for Twitter DMs. This essentially turns your Fitbit into a notification system for when someone on Twitter sends you a direct message. It's not overly useful (as you can't send a message) but it is an interesting integration.

I’ve been trying to wake up earlier in the morning. The trouble is that alarms wake everybody up, not just me. To get around this problem, I recently bought the cheapest Fitbit I could find, having learned that they have a neat silent alarm.

The truth is, if I had the cash I would rather have bought an Apple watch. When I got the Fitbit, my programmer brain immediately jumped to the question; “How can I hack this thing?” I ended up learning a bit about Fitbit, OAuth and the Twitter API. I also learned that sometimes it’s better just to get an Apple watch…

His application uses Lumen as the framework and makes connections to both the Twitter and Fitbit JSON APIs. He defines a few routes for the OAuth handling (with callbacks) and a simple view with the "Connect To" links. He shows the creation of applications on both the Twitter and Fitbit side and how to define their keys in your configuration. He sets up the Socialite providers for both connections and a bit of caching to prevent the need for a full pull. He then uses the Fitbit API to set "silent alarms" on your device that are timed to go off immediately when the app detects a new DM on the Twitter stream.

tagged: tutorial fitbit twitter api connect application alarm directmessage

Link: https://www.sitepoint.com/hacking-the-fitbit-emulating-a-pager-for-twitter-dms/

SitePoint PHP Blog:
The PHP Application Environment
Jun 16, 2016 @ 10:48:53

In this new post to the SitePoint PHP blog editor Bruno Skvorc shares a chapter from the recently released Jump Start PHP Environments from SitePoint publishing. You can order a copy of your own here.

This chapter will focus on the application environment. We’ll also discuss *AMP bundles such as XAMPP and why they’re a poor choice; production /development parity; and performance and debugging.

The remainder of the post is broken up into these main sections and also discusses topics like:

  • the differences between development, staging and production
  • the "machine pollution" that comes with the *AMP bundles
  • optimization tips about databases, front-end tools and caching

If this sample chapter was useful to you, be sure to check out and order the full book from the O'Reilly store.

tagged: application environment ebook jumpstart sample chapter

Link: https://www.sitepoint.com/php-application-environment/

Alejandro Celaya:
Using ServiceManager 3 lazy services to improve your PHP application performance
Jun 13, 2016 @ 10:20:18

Alejandro Celaya has posted a tutorial to his site showing you how to use ServiceManager 3 to improve performance in your PHP-based application. The ServiceManager is a piece of the Zend Framework.

Performance is an important subject when a project grows. There are some good practices that make projects more maintainable, like dependency injection, however, creating all the objects at the beginning of the request could reduce the application performance. If some of the created objects are not finally used, we have wasted CPU time and memory for no reason.

If we used proxies for every expensive dependency, the previous problem would be solved. We can still inject the dependency, but it will be wrapped by the proxy, which will create the object itself once we need it, or never, if it is not finally used. This is the principle behind lazy services. The ServiceManager makes use of the ocramius/proxy-manager package to create proxies on the fly for all the services configured as lazy.

He talks about the lazy_services functionality the ServiceManager provides and gives an example of it in use defining a database (PDO) connection. He talks some about how it works behind the scenes and how no code change is required to use this new configuration.

tagged: performance application servicemanager3 lazy services example tutorial zendframework

Link: http://blog.alejandrocelaya.com/2016/06/12/using-service-manager-3-lazy-services-to-improve-your-php-application-performance/

Three Devs & A Maybe:
Episode 96 - Application Performance with Jonathan Klein
May 11, 2016 @ 11:57:30

In the latest episode of the Three Devs and a Maybe podcast hosts Michael Budd, Fraser Hart, Lewis Cains and Edd Mann talk with Jonathan Klein about application performance based on some of his work creating the "High Performance PHP" course for Pluralsight.

On this weeks episode we are joined by Jonathan Klein to discuss all things application performance. We start off the show with chat about how he got into performance, why it is so important and how he thinks of it throughout the development process. From here we discuss his recently released Pluralsight course on ‘High Performance PHP’ and touch upon some of the key performance areas within the stack.

Starting with micro-optimisations at the code level, we highlight their value and caching mechanisms. We then move onto the web server, process managers and the importance of a correct configuration. The Database layer is then brought up, discussing forks of MySQL, handling slow-queries and data-denormalizations. Finally, profiling and monitoring tools are discussed (such as New Relic and Seige) and where you can typically find the most wins within a typical stack.

They talk about his Pluralsight course as well as other topics like feature flagging, caching, atomic deployments and MariaDB vs MySQL. You can listen to this latest episode either through the in-page audio player or by downloading the mp3 directly. If you enjoy the show, be sure to also subscribe to their feed to get the latest shows as they're released.

tagged: threedevsandamaybe ep96 application performance jonathanklein podcast

Link: http://threedevsandamaybe.com/application-performance-with-jonathan-klein/

Symfony Blog:
PHP-PM grows up to be a credible option for high performance PHP
Apr 25, 2016 @ 12:29:58

On the Symfony Finland site there's a post about a relatively new way to run PHP applications and how it's "growing up" to become a viable option: PHP-PM.

PHP-PM is a novel way of running PHP applications. Instead of creating an exotic high performance runtime for the PHP language, it takes an alternative route to mechanism of running PHP applications with existing runtimes.

This translates to real performance gains with existing complex applications, not just impressive theoretical benchmark results.

Instead of the usual complete bootstrap that normal PHP process goes through in its lifecycle, PHP-PM runs them as a continuous process, making for a huge boost in overall performance. The project has started gathering more momentum and is being worked on to make it a more credible platform for PHP applications.

From the humble beginnings the PHP-PM now has over 1700 stars on GitHub and a number of developers working on it. Great strides have been done since the early stages with the documentation and ease of use, but most importantly the platform now supports multiple frameworks: Symfony, Zend and Laravel.
tagged: phppm process option high performance application project symfony

Link: https://www.symfony.fi/entry/php-pm-grows-up-to-be-a-credible-option-for-high-performance-php