在没有客户端请求的情况下在服务器上运行的php脚本 [英] php script that runs on the server without a client request

查看:149
本文介绍了在没有客户端请求的情况下在服务器上运行的php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个需要在服务器上运行php脚本而无需任何请求的网站上, 它是一个机器人脚本,可以(不是全日制,而是每天至少一次)检查客户帐户,并在发生某些情况时向客户发送警报消息.

I am working on a site that require a php script running on a server without any request, it is a bot script that keeps (not full time but at least once a day) checking client accounts and send alert messages to clients when something happens.

任何想法都值得赞赏.

any ideas are appreciated.

推荐答案

假设您需要在linux上执行此操作,则可以从浏览器和CLI运行任何php脚本.

Assuming you need to do this on linux, you may run any php script from the browser and from the CLI as well.

您可以运行一个简单的php脚本: <? echo "Ana are mere"; ?>

You may run a simple php script: <? echo "Ana are mere"; ?>

像这样: php -f ./index.php

like this: php -f ./index.php

请注意文件的权限,由于此过程将连续运行,因此现在很容易看到在代码内部蔓延的任何错误,内存泄漏或未分配的变量.

Be careful about file-permissions, and any bug that may creep inside your code, memory leaks or unallocated variables will become VERY visible now, as the process will run continuously.

如果您不希望它一直在后台运行,请查看crontab(

If you dont want it running in the background all the time, take a look at crontab (http://unixgeeks.org/security/newbie/unix/cron-1.html) to be able to start jobs regularly.

-编辑-

看看 php执行后台进程PHP:如何将信息返回到等待的脚本并继续处理

基本上,您想启动后台进程,并且可以按以下顺序在自己的脚本上使用exec()或fsockopen()或file_get_contents()来执行此操作,如果无法访问exec,或套接字功能. 还可以看看 http://us2.php.net/manual/zh-CN/function.session-write-close.php ,以便后台脚本"不会阻止"请求,并且

Basically you want to start a background process, and you may do this by either using exec() or fsockopen() or a file_get_contents() on your own script probably in this order, if don't have access to exec, or socket functions. Also take a look at http://us2.php.net/manual/en/function.session-write-close.php so the "background script" won't "block" the request and http://us2.php.net/manual/en/function.ignore-user-abort.php

这篇关于在没有客户端请求的情况下在服务器上运行的php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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