30

I have heard that PHP 5.4 is faster than PHP 5.3.

Would it be ok for Drupal 7 to run under 5.4, or various contributed modules may start to break the site?

Anyway, If I use APC opcode cache, maybe 5.4, would not offer any benefit at all?

Thanks

28
+50

I have begun running Drupal 7 on PHP 5.4 myself with only minor problems in the form of notices and warnings.

On top of 7.12, you will need these two patches to fix the issues causing PHP to complain:

http://drupal.org/files/menu-link-save-1338282-15-d7.patch

http://drupal.org/files/database-query-clone-1414412-11-d7_0.patch

One of these patches has already been applied to -dev, so will be in 7.13, and the other is likely going in soon. In all cases that I can immediately think of, the bad practice causing 5.4 warnings has been bad use of array keys.

The first version of this looks like this:

$some_key = function_call();
return $some_array[$some_key];

Some times, the function call will return an array or an object, neither of which is a valid array key. In PHP 5.3, what actually, and silently happens, looks like this:

$some_key = function_call();
return $some_array[(string)$some_key];

PHP 5.4 however, warns that this may not be what you want. The second version is exactly the same, but the other way around.

$some_key = 'a_valid_key';
$may_be_a_string = function_call();
return $may_be_a_string[$some_key];

which yields an error message like

Illegal string offset 'a_valid_key'

whenever $may_be_a_string is actually a string, not an array, since the only valid string indexes are integers.

As the problems are easy to understand and the fix is (mostly) easy to apply, I've found that in several cases, -dev versions are already updated, or patches posted in the queue, that are likely to quickly go in due to their simple nature.

After some testing, I don't feel like 5.4 is "dangerous" to run in production, and I have begun running my small and personal sites on it already. I would encourage other to do the same, so we can avoid the historically slow uptake of new PHP versions.

At the time of writing, APCs latest version, 3.1.9, does not work with 5.4. I have successfully built and used it from git though.

Using APC will likely reduce the performance benefit of upgrading the PHP version, but not remove it.

  • +1 I've been wondering about this. Have you noticed any performance boosts in Drupal generally in going from 5.3 to 5.4? If you wouldn't mind posting a bit more about your experiences so far I'd be happy to award a bounty on the answer :) – Clive Apr 6 '12 at 19:12
  • In few words having APC, does not worth the trouble maybe, except if there could be significant increase in speed, which seems is not the case. – john Apr 6 '12 at 19:26
  • @Clive, I have yet to make performance measurements, although I intend to (for quite some time now). Is there something in particular you are wondering about? :) – Letharion Apr 6 '12 at 19:37
  • Sort of, yeah :) I've been toying with the idea of upgrading to 5.4 but as pretty much everything I do seems to be Drupal these days I need to be sure it's not going to make my life too much more difficult. I'm fine with patching a few modules per site but I'm worried it will soon get hard to maintain, and our production servers are still on 5.3 so I'm not sure if that would cause any problems. Any comments you had on that kind of thing, or a bit of info on what the "bad practices" are that are generally causing the warnings (to make sure my own modules are ok) would be a massive help :) – Clive Apr 6 '12 at 20:30
  • I've updated the answer with what I could. :) I keep 5.3 installed so I can easily switch back and do some performance testing. Hopefully I will remember to come back here when I've gotten to it. – Letharion Apr 7 '12 at 14:39
2

You should avoid PHP 5.4 as there is no stable APC for it. Performace for PHP 5.3 + APC would be greater than 5.4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.