Search code examples
phpapachexhp

XHP with PHP 5.4 not affecting the parser when script is called via Apache


I recently built XHP 1.5 from source, and installed it on an existing web server. The web server is running PHP 5.4.32, Apache 2.2.15 calling PHP using mod_php (not fastcgi), CentOS 6.5. All our existing PHP code (that doesn't rely on the new XHP syntax) still works great, including other extensions like Imagick, curl, and JSON.

Using a test file based on the XHP installation test:

<?php
echo "XHP!\n";
exit;
echo <a/>;
?>

This works as expected when run from the command line. (It prints XHP! then exits. The doesn't cause the parser to fail, but doesn't display either, since we're not loading in the dependencies.)

When I fetch this script through Apache, I get the error

Parse error: syntax error, unexpected '<' in /var/www/html/bloom/play.php on line 4 

Getting phpinfo() via Apache shows that XHP is loaded, extension_loaded("xhp") through Apache returns true.

What could be causing XHP to work from the command line, but to not work (not even parse) when run via Apache?


Solution

  • After looking into more detail for how my production server (not working) differed from my test servers (working) I discovered that all servers had APC 3.1.15 installed, but in production, APC's opcode cache was disabled in /etc/php.d/apc.ini:

    # BAD NEWS
    apc.enable_opcode_cache=0
    

    As it happens, this is not what we wanted for unrelated performance reasons.

    Turning on APC's opcode cache, by changing this line in /etc/php.d/apc.ini and restarting Apache caused XHP to immediately begin working:

    # WORKING
    apc.enable_opcode_cache=1
    

    I've also been able to resolve the problem by uninstalling APC altogether (although that's not practical in my app).

    That would also explain why it worked from the CLI and not from the web--all my servers have apc.enable_cli=0, so APC wouldn't interfere with XHP from the CLI.