Mosselman
Mosselman

Reputation: 1758

Fire a (multi) curl request and don't wait for the response (PHP)

I want to fire a set of PHP script (through multi_curl) and not wait for a response from the caller script (200 OK):

I have an aggregator that runs searches on social media network APIs asking them for messages. When it gets a response it fires up another search for messages that were earlier (paging). This can take quite a long time and I don't want to make users wait for this to finish.

I would like to be able to fire up a set of PHP scripts from one main script, if you will, in the background (multi_curl?) that will each take care of grabbing all these messages, each script will have its network and keyword to look on and for. I want the main script to just call these other scripts and then not wait for them to finish and just print out 'requests fired, running in background' or something of the sort. It will return JSON, so it would have to properly close and give 200 OK.

How can I do this? So fire some multi_curls and not wait for them to finish?

Upvotes: 1

Views: 1683

Answers (2)

BrandonG
BrandonG

Reputation: 367

Have a look at the PHP port of Ruby's delayed_job.

https://github.com/seatgeek/djjob

Upvotes: 1

George Mandis
George Mandis

Reputation: 791

I'm not privy to your particular setup, but you might be able to create a single script that runs your PHP scripts in the background with a bash script like this:

nohup php /path/to/script.1.php &
nohup php /path/to/script.2.php &
nohup php /path/to/script.3.php &

The ampersand at the end tells it to run the script in the background. the "nohup" command tells it to ignore any hangup signal, ensuring the script will continue running even if the user logs out.

Upvotes: 0

Related Questions