0

I am running a php script as a background process via ssh using the following command

php {path/to/script} &

I have the following error handler set in my php script:

function customError($errno, $errstr,$error_file,$error_line,$error_context)
  {
       file_put_contents('logName',"\r\nError String: ".$errstr." on line: ".$error_line,FILE_APPEND);
           file_put_contents('logName',"\r\nSome Variable Value: ".$error_context['someVariableName'],FILE_APPEND);
           file_put_contents('logName',"\r\nError String: ".$errstr." on line: ".$error_line,FILE_APPEND);
  }

set_error_handler("customError");

The script runs for a while successfully but then it stops with no error being written to the log. When it stops the message below appears in the ssh console.

{my_host_user}@{my_domain_name} [~path/to/phpfile]# Status: 500 Internal Server Error
Set-Cookie: PHPSESSID={some_sessionID}; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-type: text/html

Can anyone suggest what's going wrong and/or a good tack for debugging this.

Kenster
  • 23,465
  • 21
  • 80
  • 106
Ben Pearce
  • 6,884
  • 18
  • 70
  • 127
  • 1
    the error_handlers are not called for fatal/parse errors. For fatal errors, try to do something with `register_shutdown_function`. – bwoebi May 26 '13 at 19:49
  • echo a string at the start of your script - the code trying to send the headers will then fail and say where they stopped. – Danack May 26 '13 at 19:50
  • Weird now when I run it I'm getting a 500 internal server error immediately. @bwoebi my register_shutdown_function call back isn't triggering when this happens. – Ben Pearce May 26 '13 at 20:15
  • Judging from headers in tty, you are running `php-cgi` binary instead of `php-cli`. If you need to run some process in background, cli is a way to go. To see more detail about any error make sure to place `error_reporting(-1);ini_set('display_errors',1);` on top of your script. – dev-null-dweller May 26 '13 at 20:31
  • Hi @dev-null-dweller thanks for your suggestion. I wasn't even aware of the distinction between php-cgi and php-cli. Can you give my any starting info on how to change over. (i.e.) Is is something I change in the script or a server setting? – Ben Pearce May 26 '13 at 20:38
  • Try a `php -l file.php` to check for syntax errors? – bwoebi May 26 '13 at 20:47
  • @BenPearce cli and cgi are separate binaries, it has nothing to do with a script, so you have to check your php installation. – dev-null-dweller May 26 '13 at 20:50
  • Hi @bwoebi, could you elaborate a little. I'm not sure what a php -1 file.php is or what implementing it entails. – Ben Pearce May 26 '13 at 20:57
  • `php -l` (`l` not `1`...) is a syntax lint. – bwoebi May 26 '13 at 21:05

0 Answers0