Jump to content

Need Advice


aruns

Recommended Posts

They're used if you need to control processing if a user clicks stop while a transaction is being processed, or if a transaction times out.

 

Typically you might set a shutdown function using register_shutdown_function().

If you've set a shutdown handler, then it will be executed whenever a script terminates, eithe rbecause it has completed successfully, because the user has hit abort in his browser, or on a script timeout.

Within that shutdown function, you can use connection_aborted(), connection_status() or connection_timeout() to determine why the script has finished, and perform some appropriate action.

 

I log such events using something like:

function say_goodbye() {
if (connection_aborted()) {
	$log = fopen('/usr/local/apache/logs/timeout_cli.txt','a');
	fwrite($log,gmdate('d M Y H:i:s').' - '.$_SERVER["HOSTNAME"].' --> '.$requestMode.' script for clients '.$requestClass.' at '.$requestMethod.' aborted'."\n");
	fclose($log);
} elseif (connection_status() == CONNECTION_TIMEOUT) {
	$log = fopen('/usr/local/apache/logs/timeout_cli.txt','a');
	fwrite($log,gmdate('d M Y H:i:s').' - '.$_SERVER["HOSTNAME"].' --> '.$requestMode.' script timeout for clients '.$requestClass.' at '.$requestMethod."\n");
	fclose($log);
}
}

register_shutdown_function("say_goodbye");

 

Link to comment
https://forums.phpfreaks.com/topic/162533-need-advice/#findComment-857838
Share on other sites

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.