Does anyone know of a way to detect when a php page is finished loading? I know I can use body onload however I would like it to be able to execute some php code before closing. Something like onexit(function()); or something.
@SheldonApr 08.2008 — #You can use those two methods,
Or you can use a [url=http://php.net/register_shutdown_function]register_shutdown_function[/url]
This will run last after all processing has been completed.
[code=php] <?php
// Running this function will call the function transform() after everything else is processed. // Passing in any Varialbes you wish.
// The Caller register_shutdown_function('transform', $var1, $var2);
//The function that will run function transform($var1, $var2){ // This will never reutrn, So is only used for things like database updates or queries running the data throughput which is not need to display return "Var1: {$var1}<br/>nVar2: {$var2}n"; } ?>[/code]
@SyCoApr 08.2008 — #This will run last after all processing has been completed.[/QUOTE]
but as Felgall said, it's still before the page has even started loading. PHP is all server side. Ajax is the only way to execute PHP after a page has loaded without another page refresh.
Is use xajax as it's pretty easy way for PP developers to use ajax without having to learn reams of javascript. A simple onload(xajax_callphp()); can trigger the php function. It's pretty neat.
@fastest963authorApr 08.2008 — #I get that, i wanted to figure out when the PHP script itself finished, i was just mentioning the ajax or an onload or something because I know that happens when the PHP script finishes executing
@fastest963authorApr 08.2008 — #sorry, however it seems that I cannot edit my posts...
does anyone know of a way for javascript to kill a currently running (in the same window) php script? I know I can do a ajax load and set a session variable or something similar and then have the running code stop when that variable is set, however I was wondering if there was a javascript alternative? What I would like to be done is where a link stops a php script in an iframe and keeps the current output from the php script but stops it from running.
Thanks
Also, register_shutdown_function() worked perfectly, thanks!
@felgallApr 09.2008 — #JavaScript can't kill a running PHP script. If it were run before the page loaded it is no longer running to be killed. If it were started by an Ajax call then you can have JavaScript either disregard the response back from the PHP or launch another PHP to undo the earlier one but you can't have it interact directly to kill it.