Jump to content

[SOLVED] register_shutdown_function() behaving unexpectedly


grimpirate

Recommended Posts

I want to delete a file on any of the connection_status() conditions, be they CONNECTION_NORMAL, CONNECTION_ABORTED or CONNECTION_TIMEOUT or both abort and timeout. However, right now the function is only executing on normal and timeout and does nothing for aborted, any suggestions as to how to remedy this?

<?php
// Running on a Windows XP machine with an Apache server

error_reporting(E_ALL);

ignore_user_abort(false); // Tried both true and false neither seem to affect the behavior

function cleanup($filename){
        unlink($filename);
}

$filename = tempnam(getcwd(), 'tmp');

register_shutdown_function('cleanup', $filename);

// Purposely causes a CONNECTION_TIMEOUT
set_time_limit(20);
sleep(30);
?>

Link to comment
Share on other sites

Never mind, I managed to get it working.

<?php
// Running on a Windows XP machine with an Apache server
error_reporting(E_ALL);

ignore_user_abort(false); // Does indeed affect behavior now

function cleanup($filename){
echo 'bullcrap';
switch(connection_status()){
	case 1:
	unlink($filename);
	case 2:
	case 3:
	break;
}
}

$filename = tempnam(getcwd(), 'tmp');

register_shutdown_function('cleanup', $filename);

set_time_limit(5);
// Purposely causes a CONNECTION_TIMEOUT
do{
echo 'foo';
}while(true);
?>

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.