尝试使用CGI脚本上传图像时将其推入浏览器,但是我一直收到“ ERR_EMPTY_RESPONSE”

时间:2019-05-14 14:58:23

标签: perl cgi

我有一台CCTV摄像机,它每秒两次将JPG图像上载到服务器上的文件夹中。上传后,我想将此图像推送到浏览器。完成的结果看起来像2fps的视频。出于隐私保护的原因,我不想使用任何形式的视频供稿或任何媒体服务器,也不希望将摄像机供稿记录在任何地方,也不能倒带,暂停等...(这就是为什么JPG图像的2fps效果很好)

我在网上找到了以下代码,但似乎无法正常工作。 HTML和Javascript工作正常。但是PERL元素不是。我收到错误“ ERR_EMPTY_RESPONSE”。我的HTML / Javascript / PHP技能很好,但我的PERL知识不存在,所以我看不到错误发生在哪里。如果有人能指出正确的方向,我将非常感激。

我正在运行Ubuntu 14,PHP 7.1和Plesk Onyx 17的Linux服务器上运行它。

#!/usr/bin/perl
#
#
require 'stat.pl';
#########################################################
# Path to where the image file is stored
$DIR = "/var/www/vhosts/mydomain.com/img/";
#Filename the image is stored as
$fileName = "image.jpg";
#Maximum of images/s sent
$freq = 3;
#Max number of images to send on a connection
$maxImages = 900;
#Max number of seconds until update is considered stopped
#(ie the camera is no longer updating the image)
$maxNoUpdate = 30;
#########################################################
$con_type = "jpeg";
# Unbuffer the output so it streams through faster and better.
$| = 1;
# No input record separator when reading from file via <>.
undef $/;
# Print HTTP headers...
# NOTE: If your web server returns "Error, faulty header"
# The Line below must be commented away since your web server includes the
# HTTP/1.0 200 OK on its own.
print "HTTP/1.0 200 OK\n";
print "Content-type: multipart/x-mixed-replace; boundary=--myboundary\r\n\r\n";
$rounds=0;
#max 400 images
while ($rounds < $maxImages)
{
$rounds = $rounds +1;
$basefile = $DIR . $fileName;
@fstat = stat($basefile);
# If the same image time stamp is on the image file for more then
# X seconds then I presume that the image is no longer updated and will
# End the connection
if ($fstat[$ST_MTIME] ne $oldimagetime)
{
$sameCount = 0;
$oldimagetime = $fstat[$ST_MTIME];
}
#We may send the same image multiple times but there is a strict limit
if ($sameCount > ($maxNoUpdate * $freq))
{
die;
}
$sameCount = $sameCount +1;
$rounds=$rounds +1;
print "--myboundary\r\n";
print "Content-type: image/$con_typen\r\n\r\n";
# This is where we act
open(PIC,"$basefile");
print STDOUT <PIC>;
close(PIC); 
# Pause for 1/$freq seconds, if this time is more then a second
# we recomend you replace with sleep(NbrOfSeconds)
select(undef,undef,undef,(1/$freq));
}

0 个答案:

没有答案
相关问题