简体   繁体   English

PHP-FTP流需要的建筑建议

[英]PHP - Architechtural advice needed with FTP streaming

I've built an application which interacts with a web camera via FTP, however upon completing it I have a speed issue. 我建立了一个可通过FTP与网络摄像机交互的应用程序,但是完成该程序后,我遇到了速度问题。 The application structure is as follows: 应用程序结构如下:

Web Camera -> Proftp/Mysql -> PHP 网络摄像机-> Proftp / Mysql-> PHP

The web camera ftp's images to the Proftp server which is managed via MySQL / PHP. 网络摄像机将ftp的图像传输到通过MySQL / PHP管理的Proftp服务器。 The PHP acts as a client for users, and it in turn pulls the latest images from the FTP server. PHP充当用户的客户端,并依次从FTP服务器提取最新的映像。

This works, but is really slow. 这可行,但确实很慢。 The problem is on the Proftp -> PHP side. 问题出在Proftp-> PHP端。 Using the standard PHP ftp library it takes around 4 seconds to connect to the ftp server -> do a directory listing -> output the file contents. 使用标准的PHP ftp库,连接到ftp服务器大约需要4秒钟->执行目录列表->输出文件内容。

The speed issue is due to the authentication part of the process. 速度问题归因于过程的身份验证部分。 From what I've seen there's no way of caching/storing/serializing the FTP connection, meaning every request to the server has to start a new request. 从我看到的结果来看,无法对FTP连接进行缓存/存储/序列化,这意味着对服务器的每个请求都必须启动一个新请求。

These are the thoughts I've had so far.. 这些是我到目前为止的想法。

1) Have a PHP script run in a while loop with a permanent FTP connection open, but I know PHP isn't designed to be run in this way. 1)在一个while循环中运行一个PHP脚本,并打开一个永久的FTP连接,但是我知道PHP并非旨在以这种方式运行。

2) Create a daemon running node.js / java etc which is able to keep a permanent ftp connection open, and have PHP interact with that. 2)创建一个运行node.js / java等的守护程序,该守护程序能够保持永久的ftp连接打开,并使PHP与之交互。 What I'm worried about with this approach is the extra maintenance involved in writing more code which duplicates the authentication code already written in PHP. 我担心这种方法的麻烦是编写更多代码(与已经用PHP编写的身份验证代码重复)所涉及的额外维护。

3) ??? 3)???

Any help / suggestions would be greatly appreciated!. 任何帮助/建议将不胜感激!

将其安排在cron作业上以使FTP脚本几乎永久地或在给定的短时间间隔内运行是否明智?

Why you go the extra mile to read the images from ftp? 为什么要花更多的力气从ftp读取图像?

If they are on the same server, just read them via php directly from the storage directory. 如果它们在同一服务器上,只需直接通过php从存储目录中读取它们。

If they are not on the same server, utilize some mechanism to inform php about the latest image (for example via a text file, a GET variable etc.) and directly output http/ftp image. 如果它们不在同一服务器上,则使用某种机制来通知php有关最新图像的信息(例如,通过文本文件,GET变量等),并直接输出http / ftp图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM