By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,199 Members | 1,551 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,199 IT Pros & Developers. It's quick & easy.

Speeding up command line scripts

P: n/a
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?

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Snyke" wrote:
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?


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
Jul 17 '05 #2

P: n/a
Snyke wrote:
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?


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

But It sounds like something else is 'wrong' if it takes that long...
HTH
Pjotr
Jul 17 '05 #3

P: n/a
Snyke wrote:
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?


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.
Jul 17 '05 #4

P: n/a
"Colin McKinnon" <co**************@andthis.mms3.com> wrote in message
news:ce*******************@news.demon.co.uk...
Snyke wrote:
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?


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.


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
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.