Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 3 of 3

This is a discussion on fsock multiple times in the Shared & Semi-Dedicated forum
Currently I use an array with values from 1 to 100 roughly. For each value the array performs an fsock action where it goes to ...

  1. #1
    JPC Senior Member
    Join Date
    Mar 2003
    Posts
    74

    fsock multiple times

    Currently I use an array with values from 1 to 100 roughly. For each value the array performs an fsock action where it goes to another site and collects a small bit of data. Currently it takes roughly 2 mins to perform these 100 actions. Is there any way i can get the script to do this quicker?

    I did think of a way where you could split the original array into 5 new ones with only 20 numbers in each. Would this cut the processing time by 5 (i.e. by the 5 programs running at once)?

    If so, how could i get the five programs to run at once?
    I thought about using:

    PHP Code:
    <?
    include ("array1.php");
    include (
    "array2.php");
    ...
    ?>
    although wouldn't this just run the first array and wait for the result, then run the second one (and therefore not being quicker at all)?

    cheers

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    PHP is a very linear programming language. That's one of its downfalls. Other loaguages, like Java are multithreaded--you can run parts of your application in different threads simultaneously. When you start a thread, it runs in the background leaving your programs main thread free to do other things. PHP isn't like that. PHP runs code one instruction at a time, waiting for it to complete before going on to the next. So breaking your code up into separate pieces won't help--in fact it might even hurt performance.

    Sockets are one of the biggest bottlenecks you can come across when programming because you are relying on the speed of the network and of the remote server you are connecting to. Most sockets based programms open one or two sockets at a time. 100 is an unheard of number...

    What kind of information are you retrieving? What protocol (HTTP, FTP, etc.) Are all 100 connections coming from different servers? Is this realtime inforation or could it be cached?

    If you are getting everything from one or a few servers, it is probably possible to make multiple requests at one time instead of opening and closing a connection for each, which would improve efficiency. If you are fetching info that doesn't change very often, you may want to implement a caching mechanism where you retrieve the data once a day, once an hour, etc, depending on your needs, and store it locally either in a file or database.

    These are just a couple of things to look into that would may help your script's performance. There may be others as well, but the key is to limit the number of connections the script has to make to remote machines.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

Bookmarks

Posting Permissions

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