简体   繁体   English

同时运行PHP函数?

[英]Run a PHP function simultaneously?

What I'd like to do is use PEAR's Net_Ping package to ping a few servers to check if they are online and then display the status on a webpage. 我想做的是使用PEAR的Net_Ping包ping几台服务器,以检查它们是否在线,然后在网页上显示状态。

The problem I realized is that if I use 3 packets to conduct the ping test, that equates to about 3 seconds. 我意识到的问题是,如果我使用3个数据包进行ping测试,则大约等于3秒。 If I have to check 10 servers, that would leave the user waiting 30seconds on the page... 如果我必须检查10台服务器,那将使用户在页面上等待30秒...

Would it be possible to have my 'ping' function run 10 instances simultaneously for example, so that the user is only waiting 3 seconds instead of 30? 例如,是否可以让我的“ ping”功能同时运行10个实例,以便用户仅等待3秒而不是30秒?

I've setup my 'ping program' as a Model/Controller/View paradigm and my ping function is a method in the main controller class. 我已经将“ ping程序”设置为“模型/控制器/视图”范例,而ping函数是主控制器类中的方法。 I'd like to keep my paradigm the same if possible. 如果可能的话,我想保持我的范例不变。

You can split your ping into a script by itself and then call them asynchronously using the following method: 您可以将ping本身拆分为一个脚本,然后使用以下方法异步调用它们:

Asynchronous PHP calls? 异步PHP调用?

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

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