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:

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.