Hello Everybody.
I have the following scenario:
Web-User initiates a php script via Java JSon. The script adds some data to table and returns to the website. However, after it returns control to the user, the php script needs to initiate a second php script, but without hanging up the user's web session. Also that second script needs to run even if the user disconnects and (i.E.) shuts down his computer. That script might be running for 30 minutes.
The code I have so far work as designed, BUT it hangs the users session on the web until that seconds script is completed.
It seems that the register_shutdown_function() function does not let the 1st script return control to the user and then run the 2nd script.
Does anyone have an idea how to do this and/or what I am missing or doing wrong here?
Here is what I have so far - obviously this is a simplified version of my code. As you can see I’ve several options including disconnecting the session by instructing the client to reload the page, but the command never gets there because the 2nd script has not completed yet.
Client-Side Java script (part of a class):
Server-Side PHP script (1st script):
I have the following scenario:
Web-User initiates a php script via Java JSon. The script adds some data to table and returns to the website. However, after it returns control to the user, the php script needs to initiate a second php script, but without hanging up the user's web session. Also that second script needs to run even if the user disconnects and (i.E.) shuts down his computer. That script might be running for 30 minutes.
The code I have so far work as designed, BUT it hangs the users session on the web until that seconds script is completed.
It seems that the register_shutdown_function() function does not let the 1st script return control to the user and then run the 2nd script.
Does anyone have an idea how to do this and/or what I am missing or doing wrong here?
Here is what I have so far - obviously this is a simplified version of my code. As you can see I’ve several options including disconnecting the session by instructing the client to reload the page, but the command never gets there because the 2nd script has not completed yet.
Client-Side Java script (part of a class):
Code:
this.Initiate1stFunction = function() {
var o_Date = new Date();
d_Date = o_Date.getTime();
var cmd = "script1.php?ID1=123";
cmd += "&t=" + d_Date + "&" + d_Date;
request=null;
request = getHTTPObject();
request.onreadystatechange = sendData;
request.open("GET", cmd, true);
request.send(null);
return false
};
Code:
$arg1 = $_GET['ID1'];
$a_FinalResultData = FunctionToAddData($arg1);
//header("location: bar.php");
// header("location: ".$_SERVER['HTTP_REFERER']);
// echo ".";
ignore_user_abort(true);
set_time_limit(0);
$c_Temp = array();
$c_Temp[1]['Reload'] = '1';
$cReturnStr = json_encode($c_Temp);
print $cReturnStr;
//ob_end_flush();
flush();
ob_flush();
//sleep(10);
register_shutdown_function("Run2ndFunction", $arg1);
//header("Connection: close");
//echo "test";
//ob_flush();
die($a_FinalResultData);