cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: PHP/cURL Performance Question

From: Morgan Galpin <morgan_at_atsourceinc.ca>
Date: Fri, 18 Jan 2008 15:10:51 -0800

LovinItAll wrote:
> Hi all,
>
> I am using PHP/cURL in a script that currently is designed to reside
> on a client's PC with Apache or IIS running. Of course, I can run the
> same script from one of my dedicated servers. Here's my question:
>
> - When I run the script from a local machne under Apache, script
> execution time is +/- 15 seconds with /x/ records. The bulk of the
> time (+95%) is spent on PHP/cURL requests. All of the requests are
> sent to the same server. My upstream locally is about 1.5mbps,
> downstream = +/- 8mbps.
>
> - My remote server is on a dedicated, synchronous 100mbps port. It
> takes the same amount of time to execute the script on my remote
> server as from my local machine. Not only that, I have clients who
> have much slower internet connections (dsl, etc.). The script takes
> much longer to execute on their machines, even when they run the
> script from my server.
>
> Why? Or more importantly, how can I take advantage of my dedicated
> server's speed when running a script that uses PHP/cURL? Maybe I'm
> missing something here, but I thought the script would simply use my
> server's pipe, but apparently it isn't, and I don't want my user's
> handcuffed based on their internet connction.
>
> Just a note: If I download a 250mb file from my server, I receive it
> at nearly 8mbps, so I know the upstream from my server is 'as
> adverised'. Any help or suffestions would be appreciated. Please ask
> if you need clarification of my issue. I think I've made it clear, but
> I'm pretty close to the trees right now.
>
> Thanks,
>
> Lee
> ------------------------------------------------------------------------
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
First I would like to suggest you add some timing code to your code for
the sections you want to know about to determine where the time is
actually being spent. Then run the same script on your server, your
machine, a client machine, and on the server from a client machine.

Second, I have some guesses as to what might be the problem.

   1. I think it has not to do necessarily with the raw download speed
      of your connection, but more so with the latency with each network
      request. Try "ping"ing the target machine from each of your three
      locations. Slower connections typically have higher pings but
      there are a number of other factors. Remember each request that
      curl has to make will take about that amount of time, plus any DNS
      queries that have to be made.
   2. If it is not that, then it could be that your connection and your
      server's connection could be greater the target machine's
      connection. In these cases the target machine is the limiting
      factor in the network communication. A client machine's connection
      may be less than the target machine's connection. In this case the
      client's connection is the limiting factor.
   3. There could be a lot of data being transferred to/from the client
      machine from/to your server. If the server/client sends a lot of
      data, the client's slower connection would degrade performance.
   4. Make sure the client machine is downloading/uploading lots of data
      while running your script. egs. running a filesharing program or
      remote desktop connection.

Third, you could try making your script multi-threaded. It won't run in
a web server environment directly, but maybe there is a way for you to
get it to run at the command line. This way you could request all of the
records at the same time, or any subset of them. If network latency is
the problem and not client/server processing times, this will
significantly reduce the amount of time waiting for network data.

Anyhow, let me know how it turns out.
Morgan Galpin.
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-01-19