Speeding up command line scripts

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

    #1

    Speeding up command line scripts

    Hi.
    I have a command line script which works really fine, the only problem
    is that it take *really* long for the first output to be printed on
    screen.
    Since I also get some HTTP headers I'm suspecting that some sort of
    output buffering is used.
    How can I tell PHP to flush the buffer automatically (without using
    flush(); after every print or echo) and to remove the headers?

  • steve

    #2
    Re: Speeding up command line scripts

    "Snyke" wrote:[color=blue]
    > Hi.
    > I have a command line script which works really fine, the only[/color]
    problem[color=blue]
    > is that it take *really* long for the first output to be printed on
    > screen.
    > Since I also get some HTTP headers I’m suspecting that some sort
    > of
    > output buffering is used.
    > How can I tell PHP to flush the buffer automatically (without using
    > flush(); after every print or echo) and to remove the headers?[/color]

    Snyke, why do you have http headers in command line php. It is not
    needed. At a minimum, you can put in some conditional statements to
    take them out if running from command line (there are ways to
    auto-detect running from command line vs. from browser).

    Once that is done, it is much easier to isolate the problem.

    By the way, I have a ton of command line php code, and never seen this
    problem, so I suspect something is going on before the first echo...
    you may want to take out the code, or put in some timing echo
    statements.

    steve

    --
    http://www.dbForumz.com/ This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: http://www.dbForumz.com/PHP-Speeding...ict136881.html
    Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=457262

    Comment

    • Pjotr Wedersteers

      #3
      Re: Speeding up command line scripts

      Snyke wrote:[color=blue]
      > Hi.
      > I have a command line script which works really fine, the only problem
      > is that it take *really* long for the first output to be printed on
      > screen.
      > Since I also get some HTTP headers I'm suspecting that some sort of
      > output buffering is used.
      > How can I tell PHP to flush the buffer automatically (without using
      > flush(); after every print or echo) and to remove the headers?[/color]

      You can disable outputbuffering in the php.ini file (output_bufferi ng = off)
      and also specify if you want php to flush each time an echo or print is
      encountered.(im plicit_flush = on)

      But It sounds like something else is 'wrong' if it takes that long...
      HTH
      Pjotr


      Comment

      • Colin McKinnon

        #4
        Re: Speeding up command line scripts

        Snyke wrote:
        [color=blue]
        > Hi.
        > I have a command line script which works really fine, the only problem
        > is that it take *really* long for the first output to be printed on
        > screen.
        > Since I also get some HTTP headers I'm suspecting that some sort of
        > output buffering is used.
        > How can I tell PHP to flush the buffer automatically (without using
        > flush(); after every print or echo) and to remove the headers?[/color]

        to tell php to omit the headers:
        php -q script.php
        or if you've got an embedded interpreter directive:
        #!/usr/bin/php -q

        or if you're still using Microsoft Operating systems:
        php.exe -q script.php

        to flush the output,
        flush();

        (note this will only flush up to the last newline char)

        HTH

        C.

        Comment

        • Norman Peelman

          #5
          Re: Speeding up command line scripts

          "Colin McKinnon" <colin.deleteth is@andthis.mms3 .com> wrote in message
          news:cevi6g$701 $3$830fa17d@new s.demon.co.uk.. .[color=blue]
          > Snyke wrote:
          >[color=green]
          > > Hi.
          > > I have a command line script which works really fine, the only problem
          > > is that it take *really* long for the first output to be printed on
          > > screen.
          > > Since I also get some HTTP headers I'm suspecting that some sort of
          > > output buffering is used.
          > > How can I tell PHP to flush the buffer automatically (without using
          > > flush(); after every print or echo) and to remove the headers?[/color]
          >
          > to tell php to omit the headers:
          > php -q script.php
          > or if you've got an embedded interpreter directive:
          > #!/usr/bin/php -q
          >
          > or if you're still using Microsoft Operating systems:
          > php.exe -q script.php
          >
          > to flush the output,
          > flush();
          >
          > (note this will only flush up to the last newline char)
          >
          > HTH
          >
          > C.[/color]

          Just throw an 'ob_end_flush() ;' at the start of your script... NOT after
          every echo or print.

          Norm


          --
          Avatar hosting at www.easyavatar.com


          Comment

          Working...