PHP - Php Buffer Flushing , Is That Necesery?
PHP Buffer Flushing is it good or bad?
thank you all. Similar TutorialsI am using shell_exec, and it runs a ping on a server, is there any way to flush the buffer of the shell_exec as the data is getting written to the buffer? Because I sometimes ping a site 10 times and nothing get written until the function finishes, so is there anyway to write out the output as soon as it is available? btw, this isn't only for doing a ping it is for other things as well. Hi there, Can anyone show me how I can grab the value "c87cc576092fe1a0f5ac3d50091694b4" out of this string, it changes. Also its coming from a socket a $buffer variable, so How can I do this without grabbing everything else aswell, ie all the data after it too Quote $buffer = fgets($fp, 4096); /*** recieve data looks like this - <dd><input type="hidden" name="sid" value="c87cc576092fe1a0f5ac3d50091694b4" /> fclose($fp); } fclose($Handle); If someone could show me how to do this, I think you can do it with the split function, i just dont know how. if someone could show. i'd be SO greatful I have this inside of a method: if($output){ $opt = fread($pointer, 10000); if(!$headers){ $opt = preg_replace("/http.+(\r\n\r\n|\n\n|\r\r)/isU", "", $opt); } echo $opt; } one of my methods uses fsocketopen to open a file and start processing it. I then have this method which reads out the data to the page. as the file is being processed. Here is the file that is being processed Code: [Select] <?php function flush_buffers(){ ob_end_flush(); flush(); ob_start(); } for($i=0;$i<10;$i++){ echo "Test1: $i"; flush_buffers(); usleep(500000); } ?> when http outputs the data it also outputs the buffer size as well. I ran it on two files, and here was my output: Code: [Select] Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats 0 Test2: 0 8 Test2: 1 8 Test2: 2 8 Test2: 3 8 Test2: 4 8 Test2: 5 8 Test2: 6 8 Test2: 7 8 Test2: 8 8 Test2: 9 Is there any way to remove the buffer size (the "8" and the "b")? I basically went off of this and converted it to a class: http://phplens.com/phpeverywhere/?q=node/view/254 I'm working on a basic structure for websites containing user management and a template engine. I've run into troubles with the template engine when I try to allow for including scripted pages. This function is supposed to include and buffer the scripted page: function parse_file($file) { ob_start(); include($file); $buffer = ob_get_clean(); return $buffer; } In my template class I check to see if the data entered is a file or not, if it is then I run these lines to replace place holder-tags with the output buffer of the file included: foreach ($tags as $tag => $data) { if (file_exists($data)){ $data = $this->parse_file($data); } $this->page = preg_replace('/{' . $tag . '}|<!-- '.$tag.' -->/', $data, $this->page); } now here is the hitch, it seems the preg_replace is only replacing one of several identical place holder-tags and I am puzzled as of why this happens, could it be the buffer or what? Hi all, I post a strange behavior that could be reproduced (at least on apache2+php5). I don't know if I am doing wrong but let me explain what I try to achieve. I need to send chunks of binary data (let's say 30) and analyze the average Kbit/s at the end : I sum each chunk output time, each chunk size, and perform my Kbit/s calculation at the end. Code: [Select] <?php // build my binary chunk $var= ''; $o=9000; while($o--) { $var.= "testtest"; } // get the size, prepare the memory. $size = strlen($var); $tt_sent = 0; $tt_time = 0; // I send my chunk 30 times for ($i = 0; $i < 30; $i++) { // start time $t = microtime(true); echo $var."\n"; ob_flush(); flush(); $e = microtime(true); // end time // the difference should reprenent what it takes to the server to // transmit chunk to client right ? // add this chuck bench to the total $tt_time += round($e-$t,4); $tt_sent += $size; } // total result echo "\n total: ".(($tt_sent*8)/($tt_time)/1024)."\n"; ?> In this example above, it works so far ( on localhost, it oscillate from 7000 to 10000 Kbit/s through different tests). Now, let's say I want to shape the transmission, because I know that the client will have enough of a chunk of data to process for a second. I decide to use usleep(1000000), to mark a pause between chunk transmission. Code: [Select] <?php // build my binary chunk $var= ''; $o=9000; while($o--) { $var.= "testtest"; } // get the size, prepare the memory. $size = strlen($var); $tt_sent = 0; $tt_time = 0; // I send my chunk 30 times for ($i = 0; $i < 30; $i++) { // start time $t = microtime(true); echo $var."\n"; ob_flush(); flush(); $e = microtime(true); // end time // the difference should reprenent what it takes to the server to // transmit chunk to client right ? // add this chuck bench to the total $tt_time += round($e-$t,4); $tt_sent += $size; usleep(1000000); } // total result echo "\n total: ".(($tt_sent*8)/($tt_time)/1024)."\n"; ?> I am doing something wrong ? Does the buffer output is not synchronous ? Thanks a Lot Nunja |