note 54756 added to features.commandline

From: Date: Thu, 14 Jul 2005 12:44:04 +0000
Subject: note 54756 added to features.commandline
Groups: php.notes 
Request: Send a blank email to php-notes+get-91958@lists.php.net to get a copy of this message
dunno if this is on linux the same but on windows evertime you send somthing to the console screen php is waiting for the console to return. therefor if you send a lot of small short amounts of text, the console is starting to be using more cpu-cycles then php and thus slowing the script. take a look at this sheme: cpu-cycle:1 ->php: print("a"); cpu-cycle:2 ->cmd: output("a"); cpu-cycle:3 ->php: print("b"); cpu-cycle:4 ->cmd: output("b"); cpu-cycle:5 ->php: print("c"); cpu-cycle:6 ->cmd: output("c"); cpu-cylce:7 ->php: print("d"); cpu-cycle:8 ->cmd: output("d"); cpu-cylce:9 ->php: print("e"); cpu-cycle:0 ->cmd: output("e"); on the screen just appears "abcde". but if you write your script this way it will be far more faster: cpu-cycle:1 ->php: ob_start(); cpu-cycle:2 ->php: print("abc"); cpu-cycle:3 ->php: print("de"); cpu-cycle:4 ->php: $data = ob_get_contents(); cpu-cycle:5 ->php: ob_end_clean(); cpu-cycle:6 ->php: print($data); cpu-cycle:7 ->cmd: output("abcde"); now this is just a small example but if you are writing an app that is outputting a lot to the console, i.e. a text based screen with frequent updates, then its much better to first cach all output, and output is as one big chunk of text instead of one char a the time. ouput buffering is ideal for this. in my script i outputted almost 4000chars of info and just by caching it first, it speeded up by almost 400% and dropped cpu-usage. because what is being displayed doesn't matter, be it 2 chars or 40.0000 chars, just the call to output takes a great deal of time. remeber that. maybe someone can test if this is the same on unix-based systems. it seems that the STDOUT stream just waits for the console to report ready, before continueing execution. ---- Manual Page -- http://www.php.net/manual/en/features.commandline.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54756 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54756&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54756&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54756&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54756&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54756&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54756&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54756&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91958) next »