Jump to content

PHP does NOT execute register_shutdown_function()?


B0b

Recommended Posts

Hi everyone,

 

I got a very sexy problem here: I need to run a script for several hours and it tend to magically stop after few hours (could be 50 minutes up to a dozen hours). I decided to log some informations to spot the problem using register_shutdown_function(), which works fine when manually stopped, but the log is NOT saved (the function is NOT executed) when it crashes?! I did used an absolute path for fwrite(). I did remove all time constraints, be it ignore_user_abort( true ) or set_time_limit( 0 ). There is no related errors in PHP logs.

 

Any clue why my register_shutdown_function isn't executed?

 

:confused:

Registers the function named by function  to be executed when script processing is complete or when exit()  is called.

 

My understanding is, that 'when script processing is complete' assumes successful completion, i.e. any errors thrown cause the script to exit prematurely and thus the function is not called.

 

Try registering your logging with set_error_handler

 

[edit]

 

Well I was wrong, as this piece of code demonstrates:

<?php

function foo() {
echo 'shutdown';
}

register_shutdown_function('foo');

echo 1/0;

Thanks for the replies, guys.

 

Yes, indeed, the function got to be triggered even though the script normally finish.

 

It seems like everything on the server just dies at a certain moment. Note that this doesn't only happen with a single script, but all instances of this script and, this, all at the same moment regardless when they were started.

 

It sounds more like a server sided issue. Yet, any clue?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.