Because of the project needs, build a lot of Message Queuing also queued processing tasks, each corresponding queue also has a feed program to feed messages
At first, it was easy to do this:
while (true) { $msg$query, Bpop (); // message handlers }
In this way the feed program will never quit at first, but there is a problem, once the message handler changes, if the process is not restarted after the manual kill process, the changes will not be loaded.
Another: It is said that the PHP process runs too long to generate garbage is difficult to reclaim, need to terminate the process to reclaim process garbage.
So I say the feed program is changed to the following way:
Set_time_limit(0 ); $startTime= Time (); $maxDealNum= 1000;//Maximum processing times $maxLifeTime= 12 * 3600;//maximum life cycle duration $dealedNum= 0; while(true ) { $this->load->model (' item/category_frequently ')bdealmsg (); $dealedNum++; //The program exits when the maximum number of processing times or processing time is exceeded to clean up the memory garbage in a way that daemon restarts if($dealedNum>$maxDealNum|| ( Time() -$startTime) >$maxLifeTime) { return; } }
After each processing of a message count, as well as record feed program start execution time, if 2 people are more than a certain threshold to let the program exit, so you can avoid a single long time hungry or perform frequent scenarios will not exit the process. When the message handler changes, it can be reloaded within the expected time
Problems in implementation of Message Queuing feed program