I'm trying to do a variation of file_get_content BUT without waiting for the content. Basically I'm requesting a another php script in different url that will download a large file, so I don't want to wait for the file to finish loading. Anyone has any idea?
Thank you!
You cannot just send data without receiving an answer with HTTP. HTTP always goes request -> response. Even if the response is just very short (like a simple 200 with no text), there needs to be a response. And every HTTP socket will wait for that response.
A connectionless protocol such as UDP doesn't have the three-phase approach like TCP. It just sends the data as soon as it's ready and assumes the endpoint receives it all. UDP expects the application to put the data back together instead of the protocol used in this layer.
Short answer is no it isn't asynchronous.
I would suggest checking out either the popen function or the curl multi functions.
The simplest way would be to do:
$fh = popen("php /path/to/my/script.php");
// Do other stuff
// Wait for script to finish
while (fgets($fh) !== false) {}
// Close the file handle
pclose($fh);
If you don't want to wait for it to finish at all:
exec("php /path/to/my/script.php >> /dev/null &");
or
exec("wget http//www.example.com/myscript.php");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With