简体   繁体   English

使用php循环通过多个FTP连接的建议

[英]advice on using php to loop through multiple FTP connections

I am looking for some advice on how other developers would go about completing this same task. 我正在寻找有关其他开发人员如何完成同一任务的建议。 Essentially what I am attempting to do is loop through rows within my database to connect to multiple FTP accounts, preg_match, then output the files separate from each other. 本质上,我想做的是遍历数据库中的行以连接到多个FTP帐户preg_match,然后将文件彼此分开输出。 Here is an example of the workflow: 这是工作流程的示例:

pull connection 1
login to FTP
check preg_match against all files listed
list matching files
disconnect
...
pull connection 2
login to FTP
check preg_match against all files listed
list matching files
disconnect
...
repeat

The end result will be me creating a table with the results separate from each other. 最终结果将是我创建一个表,并将结果彼此分开。

I think the largest challenge here will be the latency time. 我认为这里最大的挑战将是等待时间。 I would look for a solution which didn't attempt to do this all in real-time, while someone was waiting for a web page to load or some other output. 我会寻找一个解决方案,在有人等待网页加载或其他输出时,不要尝试全部实时地执行此操作。 If possible I would build some API on the remote servers so I didn't have to do raw FTP requests, but could instead query for the matched results as determined on the remote server. 如果可能的话,我会在远程服务器上构建一些API,这样就不必执行原始FTP请求,而是可以查询在远程服务器上确定的匹配结果。 If needed, though, I would use PHP's cURL facility to make the connection to each external server independently, in it's own cron-driven script, with all output stored into a central database. 不过,如果需要的话,我将使用PHP的cURL工具以其自己的cron驱动的脚本独立地建立与每个外部服务器的连接,并将所有输出存储到中央数据库中。 Then the final output needed could be queried against the local database independently of fetching/matching. 然后,可以独立于获取/匹配而针对本地数据库查询所需的最终输出。

If there are many FTP connections to make and if performance is a consideration then you will want to make the connections in parallel rather than serially. 如果要建立许多FTP连接,并且考虑到性能,那么您将希望并行而不是串行进行连接。 To do this, spawn sub-processes that do the work, saving their results into a DB while the parent process waits for enough results to be created before getting the results from the DB and outputting them. 为此,请生成完成工作的子流程,将其结果保存到数据库中,而父流程会等待创建足够的结果,然后再从数据库获取结果并将其输出。

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

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