Php request url without waiting for response

I am trying to make a file_get_content option BUT without waiting for the contents. Basically I am requesting another php script in a different url that will upload a large file, so I don't want to wait for the file to finish loading. Does anyone have an idea?

Thank!

+5
source share
3 answers

I would suggest checking either popen or curl multi .

The easiest way:

$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 do not want to wait until it ends at all:

exec("php /path/to/my/script.php >> /dev/null &");

or

exec("wget http//www.example.com/myscript.php");
+2
source

Try this on a script that will load this file:

//Erase the output buffer
ob_end_clean();
//Tell the browser that the connection closed
header("Connection: close");

//Ignore the user abort.
ignore_user_abort(true);

//Extend time limit to 30 minutes
set_time_limit(1800);
//Extend memory limit to 10MB
ini_set("memory_limit","10M");
//Start output buffering again
ob_start();

//Tell the browser we're serious... there really
//nothing else to receive from this page.
header("Content-Length: 0");

//Send the output buffer and turn output buffering off.
ob_end_flush();
//Yes... flush again.
flush();

//Close the session.
session_write_close();

// Download script goes here !!!

stolen from: http://andrewensley.com/2009/06/php-redirect-and-continue-without-abort/

+2

curl_post_async .

GET PHP?

+1

All Articles