如果没有新的请求说1秒,PHP有没有办法采取一些行动(例如mysql插入)?
我想要实现的是确定从IP摄像机发送的图像序列的开始和结束.相机在检测到的移动时发送一系列图像,并在移动停止时停止发送.我知道相机每秒制作5张图像(每200毫秒).当没有超过1秒的新图像时,我想将最后一个图像标记为序列的结尾,在mysql中插入记录,将img放在适当的文件夹中(其中所有其他img来自相同的序列已经写入)并指示app在该文件夹中制作MJPEG图像剪辑.
现在我能够使用Alternative PHP cash来确定序列中的第一个图像,以节省前一个请求的参考时间,但问题是因为下一个图像序列可能在几个小时之后发生,如果有,我不能指示PHP关闭序列只有在第一次请求新序列到达时才会有一段时间没有请求.
我真的需要帮助.我的PHP几乎像我的英语一样......
我的问题的伪代码:
<?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 …Run Code Online (Sandbox Code Playgroud)