I\'m trying to do exactly the same thing as in my previous Python question, but in PHP. See my previous (answered) question
PHP script from previous question does someth
I'm having trouble getting my previous answer to work, though I suspect it may be the fault of my own server, or perhaps new browsers refusing the close the connection when instructed (I'm really not a pro on how that shtuff works).
If that method doesn't work for you, either, try this article on pseudo-multi-threading in PHP, and see if you have better luck :)
This is a bit of unix/linux-only hack that might not work on shared web servers:
file1.php
<?php
$somearg = escapeshellarg('blah');
exec("php file2.php $somearg > /dev/null &");
file2.php
<?php
//do some stuff that will take a while
//$argv should contain 'blah', and also it seems the name of the php file
//this script will continue to run. You might want to set max_execution_time to a sensible value.
If your remote script is accessible as simple webpage via http, you might try variant with http get request where response timeout set to minimal time for example via CURL:
if( $curl = curl_init() ) {
curl_setopt($curl, CURLOPT_URL, 'http://your_site/your_script.php');
curl_setopt($curl, CURLOPT_TIMEOUT, 1);
curl_exec($curl);
curl_close($curl);
}
but so you will have delay in 1 second in the your first script execution.
If a user will be using a web browser to reach the php script, I would use ajax to call the second page.
The user won't even know it is being called.
See w3schools for a tutorial on AJAX
If you need this other script to be run, depending on the client would not be wise.
What I'd do is use the technique described in the answer to this StackOverflow question (which points to this comment in the PHP documentation) and include the other script as your post-processing.
However, that comment was written in 2006, and things may have changed since then. Please give the technique a try (as I will be doing, just for fun) and see if it works for you :)
You should look into pcntl_fork if you want a multithreaded application. Also look at ignore_user_abort.