Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004

    single-threading in PHP or Perl?

    I have a PHP script that makes a call to another server, retrieves some XML, and then responds. I need to limit the calls made from my server to the server providing the XML. Lets just say, for example, that I want to limit all calls from my server to a maximum of one call every two seconds.

    As it is now, two or more user's could call this script at the same time, and since the script runs once per user, I end up making multiple calls at the same time.

    Does PHP provide any single-threaded options that would help me with what I am trying to do? I could also do it in Perl, if Perl provides any solution. I know I can do it in Java, but I do not have Tomcat running on this server, and I do not know if I want to go that route.

    Thanks for any help.

  2. #2
    Join Date
    Nov 2001
    Its not so much PHP but the nature of your web environment. Two http requests at once and you've got two calls to your script.

    You could implement a queue. User makes request; added to queue with a timestamp; if timestamp > lasttimestamp + 2seconds then do it.

    Does the remote XML change frequently? Perhaps you should just cache the result and put a time out on it. i.e. if now() > timestamp + some_timeout_value then get a fresh copy. If the XML doesn't change often, and it isn't critical that a user *always* see the most up to date (some won't in this scheme) then this is a quick and easy way out.
    “Even those who arrange and design shrubberies are under
    considerable economic stress at this period in history.”

  3. #3
    Join Date
    May 2005
    Planet Earth

    I had the same problem once, the only solution I came up with is to write in a file the number of current connections made and then decrement them.

    As you'll be using a file I recommend using a lock on the file while working on it, this way you will not end up with rights errors.

    Take a look here:

    Best regards,

    G Disrupting traditional file hosting.
    █ Signup Early and enjoy Unlimited space/bandwidth for your files hosting, Forever!
    █ No Ads.
    █ No Countdowns.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts