PHP development

Things I learned about Deployment, Test Driven Development and Continuous Integration

I’m reading a lot about Continuous Integration and Test-Driven Development lately, to work out the best ways to develop code as agile and with as much flexibility for deployment as possible. I wrote a small post earlier on Continuous Integration in PHP about how to build a CI server with Jenkins. In this post I would like to go deeper into the Why of Continuous Integration and Test-Driven Development.

In the early stage of Sugababes.nl we worked live on our production codebase, changing and testing things while users were visiting the website. That provided a lot of trouble and was soon discarded. Ever since we (my team at Sugababes first and Mobypicture later) work from SVN on development environments, commit code, try to test it in a staging environment, but most of the time we just deploy. That is, export parts of the codebase to our live environment. That is not an ideal situation and proves to be very catchy for bugs that could have been prevented. Read the rest of ‘Things I learned about Deployment, Test Driven Development and Continuous Integration’ »

Did you know session_start is a blocking call in PHP?

Did you know that session_start() is a blocking call in PHP? I didn’t and it has some importance to know:

Now I didn’t know it but is seems that php’s session handling is blocking on a per request basis. Kinda makes sense if you think about it, that if two requests simultaneously try and change a session variable then you would get constancy issues. So php handles this by making session_start a blocking action and will wait for any other request to either finish or close the session using session_write_close.

So if you have a web application or website with a lot of concurrent calls for the same user having the same session, you could run into trouble. On of the easiest fixes is to only start your session when you need it and close it as soon as possible if you are done with the session.

I never thought about session_start() being blocking and I guess neither did you, but it could have serious performance implications when you are for example serving images built by PHP. Something to consider in your next project!

via session_start blocking in php | Tomrawciffe.co.uk

How-To: Handle expired access tokens /by Facebook developers

It happens at Mobypicture all the time; expired access tokens from Facebook. There are several ways to solve this and this post at the Facebook Developer Blog handles them all. I didn’t know for example that your access tokens are rejected when you change your password at Facebook. Quite annoying actually, because I like to change my passwords once in a while and my Oauth connections should still be working afterwards.

This post will walk you through how you can ensure that you are handling and recovering from these situations gracefully. It assumes that you are familiar with our server-side authentication flow.

We will discuss 4 different scenarios:

  1. The token expires after expires time (2 hours is the default).
  2. The user changes her password which invalidates the access token.
  3. The user de-authorizes your app.
  4. The user logs out of Facebook.

/via How-To: Handle expired access tokens – Facebook developers.

Note: The solution Facebook provides only works when you have people login regularly on your website, because you need to show your users with invalid access tokens the Permission Request pop-up again.

Continuous Integration In PHP

It happens all the time while working on a big project. You fix something and something else breaks. Not because you build it as a bad piece of software, but because it is just so damn complex with dependencies everywhere.

Continuous Integration tests should catch these breaks in your application, but they are quite hard to setup. The article below goes further into the different components you can use for CI tests for PHP and even helps to set them up. I found it very helpful to read.

In simple terms, you verify that your project meets the quality standards frequently. This way, you can catch any deviation early. Doing the integration in small increments makes it easier. Implementing a continuous integration server can look difficult when you’ve never done it. In this post I will try to document how to set it up. I take for granted that you already have a LAMP server configured.

/via Continuous Integration In PHP | Eric Hogues Blog.