Results 1 to 7 of 7

Thread: multiprocessing possible?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    multiprocessing possible?

    I have found getting external webpage takes time using file_get_content function normally more than 1 second.
    Is it possible to get more than 1 webpage using multi processing at the same time so that time could be used more efficiently?

    its possible in java using multithreading i am not sure about php.

    please help me.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: multiprocessing possible?

    Async requests in PHP? Don't think I've ever heard of it.
    The fopen_wrappers can't do it. But you could write your own HTTP client with the socket primitives and use non-blocking requests. That should be possible.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    Re: multiprocessing possible?

    please little more clarification will help me to understand your suggestion

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: multiprocessing possible?

    PHP has some functions that all start with "socket_". These allow you to use sockets directly to do just about any networking you want. (Unless the socket extension is disabled or you're limited in where you're allowed to connect.)
    Among these functions are some that allow you to do non-blocking I/O, i.e. if it has no data available, it returns saying so, instead of waiting for data to become available. This allows you to check other, simultaneous connections in the meantime.

    Basically, you need to open several connections to the various things you want to fetch and check them all in turn until you've received all data.

    The thing is that these sockets really work on raw TCP connections. This means that you need to send the correct HTTP headers yourself, and you also need to interpret them yourself, e.g. send a different request if you receive a 3xx response. (Those are the redirects.) You may also have to decode the data, or de-chunk it, or otherwise handle whatever the server throws at you.

    It's certainly far more complicated than just using file_get_contents().
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    Re: multiprocessing possible?

    Oh :

    Is there any other easy solution like multithreading or something like that ?

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: multiprocessing possible?

    exec? Or a crontab scheduled script that caches the external page in a DB or something.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: multiprocessing possible?

    You could spawn an external program that fetches in parallel, yes. I'd use system() or popen() rather than exec(), though.

    PHP itself does not support multithreading, at least not within the web server.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width