PHP - Any Other Way Then Usleep?
I'm using a program to connect to a website. This program has one bug in it, if it receives data more then 500 bytes it crashes.
So on my website I've been using "usleep(100000);" which helps break up the data. Is there any other functions that can split up sending data without any type of delay? Also would a really highspeed internet put the data together with that current usleep, because with my speed it splits it up just fine. Similar TutorialsHi 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 In one of my servers when ever I call sleep or usleep functions my script sleeps and never wakes up, Any suggestion on what can cause the issue? my php -v output: Code: [Select] PHP 5.2.17 (cli) (built: Jan 24 2012 20:49:48) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies with the ionCube PHP Loader v4.0.12, Copyright (c) 2002-2011, by ionCube Ltd. |