Question

E.g

<?php

//GetParameters here

//send response/end connection

//keep executing the script with the retrieved parameters.
Was it helpful?

Solution

You could do this, it just might take some tinkering. Instead of trying to close the connection on the first script, you need to process the data with a different script.

<?php

//Get Parameters

//Send output to user

//now use curl to access other script

$post = http_build_query($_POST); // you can replace this with a processed array

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/otherscript.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);

?>

otherscript.php

<?php

header( "Connection: Close" );

// do your processing

?>

Just to explain, when curl connects it gets a connection closed header so curl quits. Meanwhile the "otherscript" is processing the data with no open connections.

I'm pretty sure using exec() may also be an option. You could simply call otherscript using php on the command line passing the variables as cmd line arguments. Something like this should work for you if you are running linux:

exec("nohup php -f otherscript.php -- '$arg1' '$arg2' < /dev/null &");

Now otherscript.php is running in the background under a different process id

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top