cURL, but with no execution delay

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

cURL, but with no execution delay

Post 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!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: cURL, but with no execution delay

Post 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 &');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Re: cURL, but with no execution delay

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: cURL, but with no execution delay

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Re: cURL, but with no execution delay

Post by someberry »

Thanks AbraCadaver, I ended up just writing a little script using a host of filesystem functions to achieve this (fsockopen and fwrite).
Post Reply