tags:

views:

42

answers:

2

Hey Guys,

I have a php script that comes down to the following:

while ($arr = mysql_fetch_array($result))
{
   $url = $arr['url'];
   exec("curl $url > /dev/null &");
} 

$url will represent a remote script.

My question is, what can I expect if I try to cycle through 2,000 URLs.

Will opening that many CURL connections cripple my server? Could I fire all 2000 in less than one minute?

What I am trying to do is prevent my users from having to setup cronjobs by opening connections and running their remote scripts for them.

Can you guys advise? I'm out of my league today.

Hudson

+3  A: 

Take a look at curl_multi_init. It will not fire multiple processes so it should be softer on your server.

I would advise you to fire only 3-15 at a time, depending on the load the server can handle and the complexity of the scripts. 2000 at a time will probably make you run out of file descriptors or other limit.

Artefacto
It may actually be cleaner and just as quick to us exec("curl $url > /dev/null
atwellpub
@atw You can configure curl to send a HEAD request instead and then the remote servers will send only headers, which you can disregard anyway (sending to /dev/null doesn't make it magically faster)
Artefacto
Say the remote script takes three minutes to complete (data compiler) would the returned HEAD act as a read receipt, and still guarantee that the connection will remain open for the entire 3 minutes?
atwellpub
@atw With another plus: with PHP, if you only make requests in batches of say 5, you can easily tell when those 5 have ended and then fire another 5. That's a bit harder to do with jobs. Of course, the best option (without going to async I/O) would be to use Java's thread pool or something to that effect so that you could always have 5 requests taking place (as soon one finished, another would be started).
Artefacto
@atw Yes, it will remain open. The only difference is the http response will have no body (the echoes/etc in the PHP script will have no effect)
Artefacto
Will it still have to wait for script completion before it opens a new connection, if the curl_multi_init is not used?
atwellpub
@atw Yes: http://www.php.net/manual/en/function.curl-exec.php Your alternative is to use non-blocking I/0. See http://netevil.org/blog/2005/may/guru-multiplexing
Artefacto
Thanks Art you've been a big help.
atwellpub
+1  A: 

You need to keep an eye on the number of opened files (connections) so you don't hit the file-max limit on your server.

Martin Wickman