不要等待file_get_contents()完成 [英] Don't wait for file_get_contents() to finish

查看:131
本文介绍了不要等待file_get_contents()完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以调用多个file_get_contents而无需等待第一个完成.我有一些PHP脚本需要做一些繁重的工作,并且一个脚本的执行时间超过1.5分钟,因此我想同时调用它们以减少执行时间.目前,我有多个file_get_contents,但是要运行下一个file_get_contents,第一个需要首先完成.我尝试了exec方法,但在服务器(共享主机)上被阻止.

解决方案

如果这是您要实现的目标,那么可以并行运行任务,但是请记住,PHP是一种高级脚本语言,其初衷是这是为了服务无状态HTTP请求.

这里有一些扩展,例如 Gearman ,该扩展允许应用程序并行完成任务.

很显然,这对您来说是个好选择,因为您可能只是在使用托管服务.从 OVH 获得的vps之类的东西要比大多数虚拟主机服务便宜.

Is there a way to call multiple file_get_contents without waiting first one to finish. I have a few PHP scripts that do some heavy work and execution time of one is more than 1.5 min so I want to call them all at the same time to reduce execution time. Currently I have multiple file_get_contents but to run next file_get_contents the first one needs to finish first. I tried exec method but it's blocked on server (shared hosting).

解决方案

Well there are ways of running tasks in parallel if thats what you're trying to achieve but bare in mind PHP is a high level scripting language and the original purpose of it was to serve stateless HTTP request.

There are extensions out there like Gearman, this extension allows applications to complete tasks in parallel.

Obviously this will be in vane for you as you're probably using a service for just hosting. Get something like a vps, a vps from OVH is cheaper than most web hosting services.

这篇关于不要等待file_get_contents()完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆