Page 1 of 1

Question about fsockopen

Posted: Wed Jun 26, 2002 9:00 pm
by Jose Arce
Hi, in another thread, romeo post something like this

Code: Select all

<?php 
$fp = fsockopen ("www.example.com", 80, $errno, $errstr, 30); 
if (!$fp) &#123; 
    echo "$errstr ($errno)<br>\n"; 
&#125; else &#123; 
    fputs ($fp, "GET / HTTP/1.0\r\nHost: www.example.com/tough.zip"); 
    while (!feof($fp)) &#123; 
        echo fgets ($fp,128); 
    &#125; 
    fclose ($fp); 
&#125; 
?>
Now, i was wondering...is there a posibility to open several fsockopen to download several files, in the same script?

I know i can download all files on a page, but one by one is kinda slow...and downloading 4 or 5 files at time will improve the speed of the script

"Pass the fork please"

Posted: Thu Jun 27, 2002 1:00 am
by BDKR
Actually, what it sounds like you may be interested in is something like fork(). This is something that PHP programmers coming from other languages have asked about at various times.

Now, there is a still experimental set of instructions called PCNTL for process control. One of the functions is pcntl_fork(). It would occur to me that spinning off child processes to handle the file downloads for you may be an option as opposed to waiting for one to complete before starting anew.

Remember, this is experimental stuff for PHP so you're heading off into uncharted waters. The phpserver project is using PCNTL and Sockets so you may want to take a look at some of it's code.

Later on,
Big Din K.R.

Posted: Thu Jun 27, 2002 4:15 pm
by Jose Arce
where can i find the phpserver project or something related to fork, i can't understand the manual...