Question about fsockopen

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Question about fsockopen

Post 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
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

"Pass the fork please"

Post 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.
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Post by Jose Arce »

where can i find the phpserver project or something related to fork, i can't understand the manual...
Post Reply