Hi!

Does anybody has a sample script witch implement "push technology" with php?
I tried to translate this cgi script (it work!) without success...

---------------- cut here ---------------
#!/bin/sh

echo Content-type: multipart/x-mixed-replace;boundary=NEXT
echo
echo --NEXT

while true
do
echo "Content-type: text/plain"
echo
date
echo --NEXT
sleep 1
done

----------------- cut here ---------------

Any help?
TIA

    <?php
    set_time_limit(10);
    header("Content-type: multipart/x-mixed-replace;boundary=NEXT\n");
    header("--NEXT");
    while(1){
    header(" Content-type: text/plain");
    header(time());
    header("--NEXT");
    sleep(1);
    ?>
    is it u want?
    however, it's NOT work!
    it make an "Internal Server Error".
    i'm using "Apache/1.3.9 Server"

      Thanks Jiri!

      I use Netscape 4.61 and PHP 4.0 and as i look in function 'plot_cam' i wrote this script:

      <?
      header("Content-type: multipart/x-mixed-replace;boundary=NEXT");

      while(1){
      print("\n--NEXT\n\n");
      header("Content-type: text/plain");
      print(time());
      sleep(1);
      echo("\n--NEXT--\n");
      }
      ?>

      But it doesn't work! This is the error:

      <br>
      <b>Warning</b>: Cannot add header information - headers already sent by (output started at /usr/local/apache/htdocs/zzz.php:5) in <b>/usr/local/apache/htdocs/zzz.php</b> on line <b>6</b><br>

      962257007

      something is wrong but i don't know what...any help?

        9 days later

        I met the problem as same as Marian's.
        Maybe should set anything in php.ini ?

        Who can help us ? 🙁

          8 days later

          hi,

          the error message is caused by "print()" and "echo()",
          since we are now adding lines into the header part of the "html", we can't output anything (even spaces/new line) before add header.
          here is the simple structure for a html file sent out form the server
          ---------begin--------------
          [header] // will not show when view source.
          // here also will store cookies infomation.
          Content-type: html/text // usually is text/html.
          [/header]
          [content] // will be show when view source

          <head>....</head>
          <body>....</body>

          [/content]
          ----------end---------------
          we are now using header() to add information into the header part,
          and echo() or print() will output to the content part.

          i hope it is helpful.

          regs,
          Ziong
          p.s. Pls correct me if i'm wrong. 😛

            Hi Ziong!

            Why don't you put a little example that really work? It's more explanatory...

            Thanks.

              a month later

              There is none error.but there is nothing to output.
              suppost I want to output the time on the server using "push".how should I write?
              thanks a lot!

                <?php
                set_time_limit(10);
                header("Content-type: multipart/x-mixed-replace;boundary=NEXT\n");
                header("--NEXT");
                while(1){
                header(" Content-type: text/plain");
                header(time());
                header("--NEXT");
                echo time();
                sleep(5);
                }
                ?>

                but I got not only the time but also a lot of warnings.(about cann't add header after output)

                so what can I do?

                  8 days later

                  Delete the sond line with:
                  ..header...text/plain..
                  after them script worked OK

                    3 months later

                    All:

                    Do you have a list of current vendors in push technology? Most documentation seems to be dated around 97/98.

                    Any help will be of great help.

                    Sresan

                      I haven't, but I think that "Marimba" is the lider...

                        6 years later
                        <?php
                          header('Content-type: multipart/x-mixed-replace;boundary="rn9012"');
                        
                          print "--rn9012\n";
                          print "Content-type: text/plain\n\n";
                          print "This is Part One\n";
                          print "--rn9012\n";
                          flush();
                        
                          sleep(5);
                          print "Content-type: text/plain\n\n";
                          print "This is Part Two\n";
                          print "--rn9012--\n";
                        
                        ?>

                        Each part is separated by the string 'rn9012', which is a random string specified in the boundary in the header. It doesn't matter what the string is as long as it doesn't occur in the content anywhere. The end is signalled with two hyphens after the random string. Once this point is reached, there are no more parts, and the connection closes.

                        Make sure to flush the output or the script will not send the content first. It might be wise to use microtime() or something to set a unique boundary every time.

                        Good luck!

                          Anon wrote:

                          All:

                          Do you have a list of current vendors in push technology? Most documentation seems to be dated around 97/98.

                          This method of HTTP push is supported only by Mozilla.

                          Not only does Mozilla have the ability to use it for resources such as web pages and images, but also has a property on XMLHttpRequest so that you can use push with client-side scripts. This is potentially quite useful, even though no other browser supports it.

                          Mark

                            Write a Reply...