[SOLVED] cURL Question

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
virdei
Forum Newbie
Posts: 8
Joined: Mon Sep 13, 2004 10:02 am

[SOLVED] cURL Question

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I would think that CURLOPT_TIMEOUT of zero would tell curl to wait indefinitely.
virdei
Forum Newbie
Posts: 8
Joined: Mon Sep 13, 2004 10:02 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
virdei
Forum Newbie
Posts: 8
Joined: Mon Sep 13, 2004 10:02 am

Post 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.
Post Reply