That is most certainly strange. Personally I would suspect the cURL module first since PHP and Apache are specifically designed to run in parallel. Perhaps it's implemented in such a way that PHP speaks to only one cURL process, that's possible, although I'd call that a catastrophic design flaw if that were the case.<div>
<br></div><div>PHP's cURL library can however do asynchronous requests, even from a single PHP execution. While it's arguably not a proper solution to the weirdness of your problem, you may have more luck with it.</div>
<div><br></div><div>Here's one tutorial that I found and looks promising:</div><div><br></div><div><a href="http://www.phpied.com/simultaneuos-http-requests-in-php-with-curl/">http://www.phpied.com/simultaneuos-http-requests-in-php-with-curl/</a></div>
<div><div><br><div class="gmail_quote">Hope it helps! Let us know. :)</div><div class="gmail_quote"><br></div><div class="gmail_quote">Kind regards,</div><div class="gmail_quote">Helgi Hrafn Gunnarsson</div><div class="gmail_quote">
<a href="mailto:helgi@binary.is">helgi@binary.is</a></div><div class="gmail_quote"><br></div><div class="gmail_quote">On Tue, Mar 15, 2011 at 4:02 PM, John Lange <span dir="ltr"><<a href="mailto:john@johnlange.ca">john@johnlange.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I have some code (written in PHP) that checks on the status of a<br>
single "server" but I need this code to scale up to hundreds of<br>
parallel checks.<br>
<br>
For example, you call the script like this:<br>
<br>
<a href="http://mytest.com/checkserver.php?ip=10.11.12.13" target="_blank">http://mytest.com/checkserver.php?ip=10.11.12.13</a><br>
<br>
where the ip=X.X.X.X is different every time depending on which server<br>
you are checking.<br>
<br>
And the PHP looks something like this:<br>
<br>
<?php<br>
<br>
$ch = curl_init();<br>
curl_setopt($ch, CURLOPT_URL, "http://".$ip."/status.html");<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br>
$output = curl_exec($ch);<br>
curl_close($ch);<br>
<br>
?><br>
<br>
To my way of thinking, this should scale easily. Lets say 200 people<br>
hit the page at the same time all passing different "ip=" values, this<br>
should check all 200 different servers in parallel and return results.<br>
<br>
It doesn't. I wrote this little bash script to test it (yes I'm using<br>
command line curl to test php-curl, please don't be confused by that):<br>
---<br>
#!/bin/bash<br>
<br>
IPS="10.18.136.20<br>
10.18.136.21<br>
10.18.136.22<br>
... ( a hundred more IPs)"<br>
<br>
for IP in $IPS ; do<br>
curl -s <a href="http://mytest.com/checkserver.php?ip=$IP" target="_blank">http://mytest.com/checkserver.php?ip=$IP</a> &<br>
done<br>
---<br>
<br>
All the curl commands launch into the background as you expect and I<br>
see all the apache child threads startup, but the results return one<br>
by one.<br>
<br>
I can't for the life of me figure out how this can be possible. Each<br>
apache thread should run it's PHP in a separate thread and return in<br>
parallel. The only thing I can think of is that php is tracking all<br>
the requests as being part of the same session and imposing some limit<br>
on the outbound curl requests... Or maybe it's apache blocking it?<br>
<br>
Just thought someone might have had to do something similar in the<br>
past and run into this.<br>
<br>
By the way, if I go direct like this:<br>
<br>
for IP in $IPS ; do<br>
curl -s http://".$IP"/status.html &<br>
done<br>
<br>
It works just exactly as you'd expect, all results return in parallel<br>
so it's got to be a problem with either PHP or apache.<br>
<font color="#888888"><br>
--<br>
John Lange<br>
<a href="http://www.johnlange.ca" target="_blank">www.johnlange.ca</a><br>
_______________________________________________<br>
Roundtable mailing list<br>
<a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
<a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
</font></blockquote></div><br></div></div>