如何在每X分钟运行我的PHP代码?

时间:2023-01-02 01:09:11

i try to make a "status monitor" for our small network. After the page was load i make a ping for every IP which i addedd. Its, ok. But i would like to do this ping in every X minute, without reload my hole page.

我试图为我们的小型网络制作一个“状态监视器”。页面加载后,我为我添加的每个IP进行ping操作。没关系。但我想每隔X分钟执行一次ping操作,而无需重新加载我的漏洞页面。

I can make it if i reload the page with header refresh, but i would like to do this witout reload.

如果我用标题刷新重新加载页面,我可以做到,但我想这样做无法重新加载。

I think i have to do this with AJAX?, But i dont know how..

我想我必须用AJAX做这个吗?但我不知道怎么做..

Thank you

谢谢

5 个解决方案

#1


0  

I'm not sure exactly what you want to do here, but this quick tutorial shows you how to call a php file every second and update a dib block with the results. It is quick and simple using jquery.

我不确定你想要做什么,但是这个快速教程向你展示了如何每秒调用一个php文件并用结果更新dib块。使用jquery快速而简单。

#2


2  

I would strongly suggest you have a look at Nagios or something similar:

我强烈建议你看看Nagios或类似的东西:

1) you don't need to have a web page constantly open to detect problems

1)您不需要经常打开网页来检测问题

2) it can automatically verify and escalate issues

2)它可以自动验证和升级问题

3) there are lots of probes available out of the box which can be used to measure all sorts of things - not just ping times

3)开箱即用的探针很多,可用于测量各种事物 - 而不仅仅是ping时间

4) responding to a ping is not the same thing as working

4)响应ping与工作不一样

5) it automatically collates stats to identify patterns of issues

5)它自动整理统计数据以识别问题模式

6) it also provides SLA type reporting

6)它还提供SLA类型报告

7) Nagios is simple enough that even I can understand it

7)Nagios很简单,即使我能理解它

8) its what I chose after a lot of work researching a replacement for a system similar to you are suggesting.

8)经过大量工作研究替换类似于你所建议的系统后,我选择了它。

HTH

HTH

C.

C。

#3


2  

If it is entire code of page i suggest setting up a cron job

如果它是整个页面代码我建议设置一个cron作业

and if you want to use ajax ( ie jquery ajax there is a plugin called jquery timer) use it send a ajax request to the page with code you want to run.

如果你想使用ajax(即jquery ajax有一个名为jquery timer的插件),请使用它向你要运行的代码发送一个ajax请求到页面。

http://plugins.jquery.com/project/timers check this out

http://plugins.jquery.com/project/timers检查一下

#4


1  

I suggest you take a look at some of the "other-way-around" approaches, such as COMET, here is an interesting article covering basic usage with PHP.

我建议你看看一些“其他方式”的方法,比如COMET,这是一篇关于PHP基本用法的有趣文章。

This would put the implementation of "ping" in your server instead of the client.

这会将“ping”的实现放在您的服务器而不是客户端。

You could for instance instead of setting a fixed interval push out updates at will. Meaning you would get almost realtime status notifications instead of the fixed interval updates.

例如,您可以不设置固定间隔,而是随意推出更新。这意味着您将获得几乎实时状态通知,而不是固定间隔更新。

In web development, Comet is a neologism to describe a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it. Comet is an umbrella term for multiple techniques for achieving this interaction. All these methods rely on features included by default in browsers, such as JavaScript, rather than on non-default plugins.

在Web开发中,Comet是一个描述Web应用程序模型的新词,其中长期持有的HTTP请求允许Web服务器将数据推送到浏览器,而浏览器没有明确请求它。 Comet是实现这种交互的多种技术的总称。所有这些方法都依赖于浏览器中默认包含的功能,例如JavaScript,而不是非默认插件。

COMET (Wikipedia)

COMET(*)

#5


1  

Why don't you try a cron?

你为什么不尝试一个cron?

#1


0  

I'm not sure exactly what you want to do here, but this quick tutorial shows you how to call a php file every second and update a dib block with the results. It is quick and simple using jquery.

我不确定你想要做什么,但是这个快速教程向你展示了如何每秒调用一个php文件并用结果更新dib块。使用jquery快速而简单。

#2


2  

I would strongly suggest you have a look at Nagios or something similar:

我强烈建议你看看Nagios或类似的东西:

1) you don't need to have a web page constantly open to detect problems

1)您不需要经常打开网页来检测问题

2) it can automatically verify and escalate issues

2)它可以自动验证和升级问题

3) there are lots of probes available out of the box which can be used to measure all sorts of things - not just ping times

3)开箱即用的探针很多,可用于测量各种事物 - 而不仅仅是ping时间

4) responding to a ping is not the same thing as working

4)响应ping与工作不一样

5) it automatically collates stats to identify patterns of issues

5)它自动整理统计数据以识别问题模式

6) it also provides SLA type reporting

6)它还提供SLA类型报告

7) Nagios is simple enough that even I can understand it

7)Nagios很简单,即使我能理解它

8) its what I chose after a lot of work researching a replacement for a system similar to you are suggesting.

8)经过大量工作研究替换类似于你所建议的系统后,我选择了它。

HTH

HTH

C.

C。

#3


2  

If it is entire code of page i suggest setting up a cron job

如果它是整个页面代码我建议设置一个cron作业

and if you want to use ajax ( ie jquery ajax there is a plugin called jquery timer) use it send a ajax request to the page with code you want to run.

如果你想使用ajax(即jquery ajax有一个名为jquery timer的插件),请使用它向你要运行的代码发送一个ajax请求到页面。

http://plugins.jquery.com/project/timers check this out

http://plugins.jquery.com/project/timers检查一下

#4


1  

I suggest you take a look at some of the "other-way-around" approaches, such as COMET, here is an interesting article covering basic usage with PHP.

我建议你看看一些“其他方式”的方法,比如COMET,这是一篇关于PHP基本用法的有趣文章。

This would put the implementation of "ping" in your server instead of the client.

这会将“ping”的实现放在您的服务器而不是客户端。

You could for instance instead of setting a fixed interval push out updates at will. Meaning you would get almost realtime status notifications instead of the fixed interval updates.

例如,您可以不设置固定间隔,而是随意推出更新。这意味着您将获得几乎实时状态通知,而不是固定间隔更新。

In web development, Comet is a neologism to describe a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it. Comet is an umbrella term for multiple techniques for achieving this interaction. All these methods rely on features included by default in browsers, such as JavaScript, rather than on non-default plugins.

在Web开发中,Comet是一个描述Web应用程序模型的新词,其中长期持有的HTTP请求允许Web服务器将数据推送到浏览器,而浏览器没有明确请求它。 Comet是实现这种交互的多种技术的总称。所有这些方法都依赖于浏览器中默认包含的功能,例如JavaScript,而不是非默认插件。

COMET (Wikipedia)

COMET(*)

#5


1  

Why don't you try a cron?

你为什么不尝试一个cron?