Browser ends PHP infinite loops and then prints the data -


i trying capture live feeds card reader , printing using php.

<?php     $i=0;     for(;;)     {         $subdata=file_get_contents("/home/openflow/subscribedata.txt");         $subdata2=file_get_contents("/home/openflow/subscribedatatemp.txt");          if($subdata!=$subdata2)         {             copy("/home/openflow/subscribedatatemp.txt","/home/openflow/subscribedata.txt");             $sub=file_get_contents("/home/openflow/subscribedata.txt");             $i++;             echo "\n". $i."--".$sub;         }     } ?> 

i using loop infinite loop. whenever there new data, card reader script writes subscribedatatemp.txt file , above script checks difference between subscribedatatemp.txt (the latest entry) , subscribedata.txt (the previous entry). if there's difference, should copy latest onto previous , echo latest data.

the problem when executing php code above, doesn't show while , after sometime browser stops loading , displays data got in loading time.

this indicates loop execution getting stopped , data being printed after end of while loop, right? how can correct this?

at top of code, add line:

set_time_limit(0); 

so whole code looks this:

<?php set_time_limit(0); $i=0; for(;;) { $subdata=file_get_contents("/home/openflow/subscribedata.txt"); $subdata2=file_get_contents("/home/openflow/subscribedatatemp.txt");  if($subdata!=$subdata2) { copy("/home/openflow/subscribedatatemp.txt","/home/openflow/subscribedata.txt"); $sub=file_get_contents("/home/openflow/subscribedata.txt"); $i++; echo "\n". $i."--".$sub; } } ?> 

read more on set_time_limit() here.

also, check if max_execution_time in php.ini file not set.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -