Is there any way in PHP to take some action (e.g. in mysql insert) if there are no new queries for 1 second?
What I'm trying to achieve is to determine the beginning and end of a sequence of images sent from an IP camera. The camera sends a series of images to the detected motion and stops sending when the motion stops. I know that the camera takes 5 images per second (every 200 ms). When there are more than 1 second of new images, I want to mark the last image as the end of the sequence, insert the record in mysql, put the img in the appropriate folder (where all the other img from the same sequence are already recorded) and specify the application to make the MJPEG clip of the images in this folder.
Now I can determine the first image in the sequence using Alternative money in PHP to save the original time from the previous request, but the problem is because the next sequence of images can happen in a few hours, and I can not instruct PHP to complete the sequence if for some There are no NO requests for time only when the first request for a new sequence arrives.
I really need help with this. My PHP sucks almost like my English ... :)
Pseudocode for my problem:
<?php if(isset($headers["Content-Disposition"])) { $frame_time = microtime(true); if(preg_match('/.*filename=[\'\"]([^\'\"]+)/', $headers["Content-Disposition"], $matches)) { $filename = $matches[1]; } else if(preg_match("/.*filename=([^ ]+)/", $headers["Content-Disposition"], $matches)) { $filename = $matches[1]; } } preg_match("/(anpr[1-9])/", $filename, $anprs); $anpr = $anprs[1]; $apc_key = $anpr."_last_time"; //there are several cameras so I have to distinguish those $last = apc_fetch($apc_key); if (($frame_time - $last)>1) { $stream = "START"; //New sequence starts } else { $stream = "-->"; //Streaming }; $file = fopen('php://input', 'r'); $temp = fopen("test/".$filename, 'w'); $imageSize = stream_copy_to_stream($file, $temp); //save image file on the file system fclose($temp); fclose($file); apc_store($apc_key, $frame_time); //replace cashed time with this frame time in APC // here goes mysql stuff... /* Now... if there is no new requests for 1 second $stream = "END"; calling app with exec() or similar to grab all images in the particular folder and make MJPEG... if new request arrives cancel timer or whatever and execute script again. */ ?>
php image ip-camera
Gawran
source share