By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,349 Members | 1,353 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,349 IT Pros & Developers. It's quick & easy.

Multiple threads/connections in cURL

P: 93
Hi, I am using cURL with php to submit a form to a website and then retrieve the page that comes back. That part is easy. The problem is that the site I am posting the request to displays a 'please_wait' page which then redirects you to the page that you actually want to see. I can deal with this fine if I am only sending one request, but the trouble is that I am sending lots of requests (i.e. I am posting the form several times with different form data in each request). If I do this one after the other then I have to post the first request, then wait a couple of seconds and then request the page with the info on it. Then post the next request, wait a few seconds, get the page. Send the next.......ZZZzzzzz

So I need to be able to do them all at once...which cURL can do. But the trouble is that the 'please wait' page redirects you using javascript, so cURL can't automatically pick this up i.e. the CURLOPT_FOLLOWLOCATION doesn't work. The only way to do it is to post the request, and get the 'please wait' page, and then send a separate request for the page with the info on it.

And here's the snag: Posting the request and getting the info page all has to be done on the same connection, otherwise the website that I'm getting the page from doesn't know which page to send me!!

So I need to run several simultaneous cURL connections, then wait a couple of seconds and then USING THE SAME CONNECTIONS send 'GET' requests for the resulting pages.

May 10 '07 #1
Share this Question
Share on Google+
3 Replies

P: 93
I think it might be possible to write a script that posts the request and then requests the resulting page. And then get cURL to access that script on my server lots of times all at once. But I can't work out how to do this.
May 10 '07 #2

P: 93
The answer: There's no need to keep the same connection.

HTTP is 'stateless' meaning that a server has no way of tracking which user is which just by keeping the connection. The only way a server can determine which user is which (or which request is which) is by putting a cookie onto the user's computer to track who they are. (Or a user could be tracked using hidden form fields.) I had made a mistake in the way that I was dealing with the cookies which falsely led me to believe that there was something else affecting how the server was determining which request was which.

This explains it:

For anyone looking for how to do multiple cURL transfers look at the example at the bottom of this page of the php manual:
May 11 '07 #3

Expert 5K+
P: 5,058
I'm glad you solved your problem and thank you for sharing the solution with us.
May 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.