Work has such a scene, 1, the amount of data is very large, 2, the need for data in real-time simple processing. For example, a user-published message is written to the Message.txt file in real time and pushed into the MCQ (using a PHP script) while writing. Then this simple function is more suitable for the use of the PHP flow of the processing method to achieve. php://is a URL-style encapsulation protocol that has been registered in PHP to access individual input/output streams (I/O streams).
# php Script mcq.php
<?php $STD fopen ("Php://stdin", "R"); while (($linefgets($stdfalse ) { // pushes the resulting data into MCQ Put_mcq ($line);}
Fclose ($STD);
#shell Script
# sread is a real-time access to message.txt file data in a script, user-published messages are written to message.txt files in real time
Sread message.txt |/bin/php mcq.php
Optimizations: Simple stdin constants are recommended in the PHP manual
<?php
while ($linefgetsfalse ) { // pushes the resulting data into MCQ PUT_MCQ ($line);}
Stream Processing for PHP