How can Sending multi http request at the same time?
Moderator: General Moderators
How can Sending multi http request at the same time?
Hi all,
Please tell me the way we sending and retrieving multi http request at the same time.
Thanks
Please tell me the way we sending and retrieving multi http request at the same time.
Thanks
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I don't understand the question.
Could you explain in a little more detail please.
Maybe fsockopen is what you're looking for?
Could you explain in a little more detail please.
Maybe fsockopen is what you're looking for?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Sorry because of my unclear question.
Here is the code I send one http request
The problem is when I send 3 http requests it takes a lot time to wait each $http call $http->Get() functions. Can we make these http requests asynchronously? Can we have another way to sent all http requests and retrieving it later?
Here is the code I send one http request
Code: Select all
for ($i=0; $i<3; $i++) {
&http = new httpClient();
if ($http->Connect('www.ups.com', 80)) {
$http->addHeader('Host', 'www.ups.com');
$http->addHeader('User-Agent', 'osCommerce');
$http->addHeader('Connection', 'Close');
//echo "e;attempt : "e; . $request . "e;<br>\n"e;;
if ($http->Get('/using/services/rave/qcostcgi.cgi?' . $request)) $body = $http->getBody();
$http->Disconnect();
} else {
return 'error';
}
}http://uk2.php.net/fsockopenhiposang wrote:Hi onion2k,
Can you tell it in detail? Do you have any documents about it?
Another way, in "for" loop statement, can we raise 3 php pages ,each page take on 1 http request and then retrieve data later?
thanks.
http://uk2.php.net/manual/en/function.s ... ocking.php
Open 3 sockets, set them all as non-blocking, then write proper HTTP requests to each socket to start things going. Then keep looping round using a while loop or something checking if there's anything to read from each one (using stream_get_contents() ). Keep looping until you have all the required data or else they timeout.
That should work. But like I said before, writing the code will be complicated.
- IceMetalPunk
- Forum Commoner
- Posts: 71
- Joined: Thu Jul 07, 2005 11:45 am
You could always use a FOR loop, and include PHP files. So if you wanted 3 PHP pages, you make 1 that receives the files to call, like this:
$files would be an array containg all the files to include. It wouldn't be simultaneous, but it will be darn close.
-IMP

Code: Select all
<?php
for ($i=0; $i<count($files); $i++) {
include $files[$i];
}
?>-IMP