Page 1 of 1

[SOLVED] cURL Question

Posted: Mon Oct 04, 2004 1:06 pm
by virdei
feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


 

I have a curl script on page 1 that will post some values to page 2. Currently when page 1 performs the post using curl, page 1 stays waiting for a response from page 2. I don't want page 1 to sit idly by until page 2 returns something. I want page 1 to do the post with curl and continue executing any code left on that page. In other words, i want this post to be asynchronous. Below I have posted my script for the curl post. Any help will be greatly appreciated.

Code: Select all

$posturl = "url i'm posting to"; 
$postvalues = "var1=val1&var2=val2"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$posturl); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,0); 
curl_setopt($ch, CURLOPT_TIMEOUT, 0); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvalues); 
curl_exec($ch); // this is where it stays waiting until something returns from page 2.

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Oct 04, 2004 1:12 pm
by feyd
I would think that CURLOPT_TIMEOUT of zero would tell curl to wait indefinitely.

Posted: Mon Oct 04, 2004 1:18 pm
by virdei
I see what you mean about the CURLOPT_TIMEOUT. Sometimes the best answers are the simplest ones. I'll have to test that later on today and hopefully it will work. I'll inform you after I test. And I apologize for forgetting the

Code: Select all

tags.

Posted: Mon Oct 04, 2004 1:21 pm
by feyd
if you don't want it to wait at all, you could potentially either wait until the end of the script to tell it to execute, or use [php_man]fsockopen[/php_man]() to create the request, but not read the details.. maybe.. although I'm not sure if fsockopen would wait for a response or not..

Posted: Mon Oct 04, 2004 2:07 pm
by virdei
I changed the CURLOPT_TIMEOUT to 1 second and now it works beautifully. It waits 1 second for a response and then it continues. It works great since i don't really care what page 2 returns. Thanks for your help.