Some PHP cron jobs started failing on a shared server recently. They had been working without error and no updates for nearly a year, but now would no longer run due to syntax errors. What was going on?
It turns out these scripts were suddenly now running under PHP 4, not PHP 5. There is a version of PHP 4 installed at /usr/local/bin/php, but this was the "shebang" line on these scripts:
I did some experiments:
% /usr/local/php5/bin/php --version PHP 5.2.6 (cli) (built: May 11 2008 13:09:39) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies % echo '<?= phpversion() ?>' | /usr/local/php5/bin/php 5.2.6 % printf '#!/usr/local/php5/bin/php\n<?= phpversion() ?>' > version % chmod +x version % ./version 5.2.6 % mv version x.php % ./x.php 4.4.9
I didn't know Linux would let file extensions override shebang lines, but that's what I'm seeing. Support at the hosting company had no idea why this was happening (or what had changed recently to make it happen), so I went with a workaround: rename the scripts so they no longer end in ".php".
The cron jobs are running again, but I hate a "just don't do that" answer. I'm really curious to know where this behavior is coming from, because I've never seen anything like this from *nix at the shell level. I tested under both zsh and bash, so I don't think I can blame a shell configuration. I grepped for 'php' under /etc to see if that would give me any clues, but no. Any ideas?