TeAmEr
TeAmEr

Reputation: 4773

how to run a php when the current script finishes

how to run a php when the current script finishes using curl ? cant use shell or set_time_limit to loop the script .

EDIT: I want to be able to use curl to call the same script , but when i use curl_exec , i don't want the script to wait till curl finishes , i just want it to call the page and keep moving on without waiting curl to finish .

EDIT:

using this code on the start of the script

ignore_user_abort(true);
header("Content-Length: 0");
header("Connection: close");
flush();

then using curl to make the script call it self works on windows , but on linux it doesn't ! aka , i want curl to call a page and not wait for a response

Thanks

Upvotes: 0

Views: 556

Answers (2)

TeAmEr
TeAmEr

Reputation: 4773

Found it :

adding this to the start of the script :

ignore_user_abort(true);
header("Content-Length: 256");
header("Connection: close");
echo(str_repeat(' ',256));
@ob_flush();
@flush();
@ob_end_flush();

then call this 1_script from another 2_script via curl allows the other 2_script to complete its process without waiting for 1_script to finish ! . it's just that curl won't read the "connection:close" header before 256 byes are recieved , so we send them via spaces :)

Upvotes: 1

stivlo
stivlo

Reputation: 85476

You want to be able to run a CURL request without waiting for it.

Normally, you'd start a new thread to run the CURL request in it, but PHP doesn't have support for multithreading.

With popen or proc_open, you can run a background process, if you're allowed to use it. You could run a CLI PHP script to execute your CURL request.

Another idea is just write the request in a DB table, and have a cron CLI script poll that table every X minutes and execute any pending request.

Upvotes: 3

Related Questions