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

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

SitePoint PHP Blog:
PredictionIO and Lumen: Building a Movie Recommendation App (Part 2)
Apr 06, 2016 @ 14:30:42

The SitePoint PHP blog has posted the next part in their series about using Predictive.IO and Lumen to create a simple movie recommendation application (part one is here). In this second part of the series they build on the environment created in the previous article and start developing the actual application.

In the intro, we covered the basics of PredictionIO and installed its dependencies. In this part, we’re going to build the movie recommendation app.

The tutorial starts with a brief configuration section to ensure you have your API keys configured correctly. Then it gets into the code:

  • Pulling the data from the Movie DB API
  • Creating the endpoint to perform the endpoint
  • Picking random movies to show the user and recording their reactions (like/dislike)
  • Creating the endpoint to recommend movies

Finally they share the configuration to set up the application deployment and train it with some example content you provide through some basic interactions. Finally they help you set up a cron job to train and redeploy the application every five minutes with the latest interaction information.

tagged: tutorial predictionio series part2 movie recommendation implement application

Link: http://www.sitepoint.com/predictionio-and-lumen-building-a-movie-recommendation-app/

SitePoint PHP Blog:
PredictionIO: Bootstrapping a Movie Recommendation App
Apr 05, 2016 @ 11:22:11

On the SitePoint PHP blog they've posted a tutorial showing you how to use the Prediction.IO server to create a movie recommendation application. Prediction.io is "an open source Machine Learning Server built on top of state-of-the-art open source stack for developers and data scientists create predictive engines for any machine learning task".

In this tutorial, I’m going to walk you through PredictionIO, an open-source machine learning server, which allows you to create applications that could do the following: recommend items (e.g. movies, products, food), predict user behavior, identify item similarity and rank items.

You can pretty much build any machine learning application with ease using PredictionIO. You don’t have to deal with numbers and algorithms and you can just concentrate on building the app itself.

The tutorial, the first part of a series, refreshes some older instructions for getting the Prediction.IO system up and running. He walks you through the creation of an AWS instance for the server a few different ways (Vagrant, Docker, etc). He then talks about the use of the Movie API from MovieDB and the two parts of the application that will be implemented on top of it: a learning phase and a recommendation phase. They show how to use Prediction.io to create the recommendation engine and make the new application on top of it. He helps you install some dependencies to use in the PHP side of the application and briefly explains what they're for.

This wraps up part one of the series. In the second part he starts putting this all to use and creates the PHP functionality to lay on top of the machine learning engine and handle learning and recommendations for users.

tagged: predictionio machinelearning server tutorial movie recommendation application part1 series

Link: http://www.sitepoint.com/predictionio-bootstrapping-a-movie-recommendation-app/

Mohamed Said:
Building an API for 3rd party applications
Mar 30, 2016 @ 09:30:31

In this post to his site Mohamed Said shows you how to build an API that allows for easier integration with your content/functionality by 3rd party applications. This example uses the Laravel framework but the ideas could be applied in any framework.

APIs are cool, & laravel can handle all the coolness you may desire. Here we talk about building an API for third party applications and allowing them to communicate with your application on behalf of users.

He starts where any good project should: planning for what features need to be included and the flow of the request/response process. He then walks you through the whole process for setting up the API:

  • Updating the routes for the API request endpoints
  • Creating the new Auth and Home controllers
  • Setting up the migration for the "applications" table
  • Using the firebase/php-jwt library for authentication/authorization handling
  • Registering a token and validating it on the incoming request

He wraps up the post talking about user authentication via a simplified OAuth-ish process flow, making requests using the resulting token and logging the user out (expiring the token).

tagged: api tutorial laravel application integration jwt token authentication authorization

Link: http://themsaid.github.io/laravel-api-3rd-party-20160327/