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!
cURL, but with no execution delay
Moderator: General Moderators
- 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
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.
Re: cURL, but with no execution delay
I was hoping not to have to spawn another PHP process. That just seemed... ugly.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 &');
- 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
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.
Re: cURL, but with no execution delay
Thanks AbraCadaver, I ended up just writing a little script using a host of filesystem functions to achieve this (fsockopen and fwrite).