1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simultaneous file_get_contents() to different APIs

Discussion in 'PHP' started by ErectADirectory, Apr 23, 2007.

  1. #1
    Hello fellow geeks,

    I'm writing a script that goes out and gathers information from a few well known APIs and then combines the results in an easy to use format. At this point, I am wanting to speed the process up by having the file_get_contents() happening at the same time instead of 1 completely evaluating before calling the next one.

    As it is, the program takes 5-10 seconds to complete processing before returning a result. If I were to connect to the different APIs at once, I could easily cut that time in half.

    I'm not a noob so you don't have to do extensive coding to answer my question, just a push in the right direction is what I am looking for.

    Thanks in advance,
    EAD
     
    ErectADirectory, Apr 23, 2007 IP
  2. Weizheng

    Weizheng Peon

    Messages:
    93
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    pcntl_fork();
    PHP:
     
    Weizheng, Apr 23, 2007 IP
    ErectADirectory likes this.
  3. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Should have dug around the manual a bit more before posting. Thanks a million Weizheng for the answer. Unfortunately ...

    "Process Control should not be enabled within a web server environment and unexpected results may happen if any Process Control functions are used within a web server environment"

    And yes, it is disabled on my server. Perhaps a VPS where I have more control might be the right answer for this but it seems a bit expensive for just the ability to use this function. Traffic does not justify the cost @ this point.

    Anyone else?

    Rep given freely for help on this
     
    ErectADirectory, Apr 23, 2007 IP
  4. Weizheng

    Weizheng Peon

    Messages:
    93
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the rep.

    Have you considered executing an outside program via exec() or system()?
     
    Weizheng, Apr 23, 2007 IP
  5. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Not really, but I will as I've always wanted to tinker with Python. This might be a good excuse to.

    ... Considered that anything was outside of the scope of PHP ... never!

    So, what you are saying is that because of my server's settings, PHP would probably not be the best tool for the job. I should call an outside program for this functionality.

    2 questions about that statement:

    1> Anyone know a server that allows you to run Process Control Functions (the pcntl family of functions).

    2> Is Python user friendly enough to try out for this or should I go back to Perl, as this was my first language to play around with. I, gladly, left it years ago when I realized how logical PHP was to me.

    Thx in advance
     
    ErectADirectory, Apr 23, 2007 IP
  6. Weizheng

    Weizheng Peon

    Messages:
    93
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Since you're in shared hosting, I guess all the risky functions should have been disabled. You can do a phpinfo() and check the "disable_functions" field. See if exec(), system(), passthru() and popen() have been disabled.

    If they are you still have a little hope - check if you've PHP version 5. If it is then you can try using the multi threaded (and undocumented) url grab function - curl_multi_exec().
     
    Weizheng, Apr 24, 2007 IP