douzhang1926 2009-08-27 13:02
浏览 73
已采纳

在没有客户端请求的情况下在服务器上运行的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.

  • 写回答

6条回答 默认 最新

  • dtn43447 2009-08-27 13:07
    关注

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

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

    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.

    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.

    -- edit--

    take a look at php execute a background process and PHP: How to return information to a waiting script and continue processing

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路