Skip to content

Instantly share code, notes, and snippets.

@jerclarke
Last active May 23, 2016 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerclarke/3eda29aa165f706fb5fe96ed30259656 to your computer and use it in GitHub Desktop.
Save jerclarke/3eda29aa165f706fb5fe96ed30259656 to your computer and use it in GitHub Desktop.
<?php
/*
* Simple function to intentionally crash HHVM and trigger our PHP-FPM fallback
*
* For whatever reason having two "default:"" clauses in a switch statement crashes HHVM but not PHP-FPM
* In HHVM error logs it causes: Fatal error: Switch statements may only contain one default: clause in /var/www/sites/monittest/index.php on line XX
*
* This can be used to intentionally trigger a fallback from HHVM to PHP-FPM in our system, which normally happens
* to avoid scripts with rare HHVM bugs from crashing completely to WSOD, and to keep the server mostly working
* if HHVM failed completely, which has happened a couple of times.
*
* We need our monitoring script to be able to differentiate between success with HHVM and success with PHP-FPM,
* so that we can be notified when the fallback is being used and work to repair HHVM. This can be done accurately
* with a call to `if (defined('HHVM_VERSION')){}` but that doesn't give us a way to instigate the fallback to
* PHP-FPM as it would happen in the wild.
*
* This function is designed to crash HHVM and trigger the fallback by triggering an error in HHVM and forcing
* PHP-FPM into action. We can use this to make sure the monitoring script reacts as we expect to the fallback.
*
* Note that this function never needs to be run, it's mere presence with two default: clauses will crash the script.
* Uncomment the second "default:" and reload to trigger PHP-FPM fallback mode
*/
function gv_test_hhvm_active() {
$demo_variable = '';
switch ( $demo_variable ) {
case 'demo_case':
break;
default:
/*
* Double default clause breaks HHVM but not PHP-FPM
* Uncomment second default: below to force HHVM to fail and test
* the fallback to PHP-FPM
*/
// default:
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment