Page 1 of 1

cURL, but with no execution delay

Posted: Wed Dec 16, 2009 10:43 am
by someberry
Hi, I've built a small script for the company I work for which updates a database from a user request. Whenever it is updated I would like to fire a request to a URL (example.org/example.php) informing it of the new database value.

Some caveats:
- These two sites are completely independent, and I do not have access to example.org, so I have to update it via a URL.
- The request needs to send POST data.

None of the above is a problem, but this one is:

- The user should not be delayed if the other server is down/slow.

If I use cURL then is it blocking? I.e. will the execution of PHP be held up whilst it tries to connect to the other server? Ideally I would like to fire the request and not even care if it gets there successfully (kinda the opposite of the TCP IP!) so long as the user who initiated the initial database update doesn't have to wait.

Thanks!

Re: cURL, but with no execution delay

Posted: Wed Dec 16, 2009 11:06 am
by AbraCadaver
I'm not sure of all of the settings for curl, but you can exec() the curl code and put it in the background:

Code: Select all

exec('/usr/bin/php /path/to/curl_file.php > /dev/null &');

Re: cURL, but with no execution delay

Posted: Wed Dec 16, 2009 11:10 am
by someberry
AbraCadaver wrote:I'm not sure of all of the settings for curl, but you can exec() the curl code and put it in the background:

Code: Select all

exec('/usr/bin/php /path/to/curl_file.php > /dev/null &');
I was hoping not to have to spawn another PHP process. That just seemed... ugly.

Re: cURL, but with no execution delay

Posted: Wed Dec 16, 2009 12:54 pm
by AbraCadaver
I guess you could use fsockopen() and stream_set_blocking(). You would have to build your own post request. I saw a curl non-block example but didn't have time to dissect it as I don't often use curl.

Re: cURL, but with no execution delay

Posted: Wed Dec 16, 2009 1:00 pm
by someberry
Thanks AbraCadaver, I ended up just writing a little script using a host of filesystem functions to achieve this (fsockopen and fwrite).