Streaming text output.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Handover Phist

    Streaming text output.

    I have a call to wget that transferres a file of about 30 meg at about 1
    meg per second. This has the user waiting 30 seconds or so before the
    page responds. What I want to do is send the ouput of wget while it's
    happening, which is proving a bit iffy.

    $modprog = popen('/path/to/wget/shell/script', 'r');
    $buffer = fopen($modprog, "1");
    $display = fgetc($buffer);
    echo $display;
    pclose($modprog );

    doesn't work for what may be obvious reasons to those in the community.
    I don geddit. Any suggestions please?

    --
    Virtue is its own punishment.
  • Nikolai Chuvakhin

    #2
    Re: Streaming text output.

    Handover Phist <jason@jason.we bsterscafe.com> wrote
    in message news:<slrnbuets b.16r.jason@jas on.websterscafe .com>...[color=blue]
    >
    > I have a call to wget that transferres a file of about 30 meg
    > at about 1 meg per second.[/color]

    Why do you have to involve wget at all? Let's say you need to
    dump into the standard output a file that resides at this URL:



    Here's what you can do:

    $host = 'www.yourhost.c om';
    $path = 'your/path/your.file';
    $fp = fsockopen ($host, '80');
    if ($fp) {
    fputs($fp, 'GET '.$path." HTTP/1.0\r\nHost: ".$host."\r\n") ;
    } else {
    die ('Oops... Nobody home...');
    }
    while (!feof ($fp)) {
    echo fgets ($fp, 10240);
    }
    fclose ($fp);

    Another workable alternative would be to use cURL:

    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    By default, curl_exec() will do exactly what you want: dump
    a remote file into the standard output...

    Cheers,
    NC

    Comment

    • Rahul Anand

      #3
      Re: Streaming text output.

      Handover Phist <jason@jason.we bsterscafe.com> wrote in message news:<slrnbuets b.16r.jason@jas on.websterscafe .com>...[color=blue]
      > I have a call to wget that transferres a file of about 30 meg at about 1
      > meg per second. This has the user waiting 30 seconds or so before the
      > page responds. What I want to do is send the ouput of wget while it's
      > happening, which is proving a bit iffy.
      >
      > $modprog = popen('/path/to/wget/shell/script', 'r');
      > $buffer = fopen($modprog, "1");
      > $display = fgetc($buffer);
      > echo $display;
      > pclose($modprog );
      >
      > doesn't work for what may be obvious reasons to those in the community.
      > I don geddit. Any suggestions please?[/color]

      I think popen returns a file pointer so you do not need

      $buffer = fopen($modprog, "1");

      You can directly call

      $display = fgetc($modprog) ;

      Hope it will help....

      --Rahul

      Comment

      Working...