PHP利用监控宝来执行Whmcs的自动任务

WBOY
Release: 2016-06-20 12:51:23
Original
1240 people have browsed it

好吧,其实是用Linux的计划任务完全可行,不过…不会-_-

想了想,可以利用监控宝的定时访问的特征,来执行Whmcs的定时任务.

可是,纠结的地方来了…监控宝最长的监控间隔是1小时…

因此,这段代码就诞生了…

首先,分析一下,假若监控宝每隔1小时会访问一次指定的URL,这样就需要一个计数器,又因不能常驻内存,写SQL麻烦,so,使用文件存放.

一天24小时,监控宝会访问24次,但是,监控宝会有两个节点同时访问,因此24*2=48.

对php不熟,所以这里不考虑并发的问题.由于涉及到文件操作,所以,没有权限是不行的

放出代码..

<?php    /*    * URL: www.okss.net  */    set_time_limit(0);    $fileName = "count.love";    $urls = array("http://my.getvm.net/cron.php"        ,"http://billing.getvm.com/cron.php");    //如果文件不存在    if(!file_exists($fileName))    {        CreateFile($fileName,0);        exit();    }    if (!is_readable($fileName)) {        //文件不存在或者无法读取        die('File does not exist or could not be read!');    }else    {        $count = file_get_contents($fileName);        $count++;        if($count>=48)        {            //监控宝有两个节点同时访问,所以这里不是24小时            foreach ($urls as $key => $value) {                file_get_contents($value);            }            $count=0;        }        echo"$count";        DeleteFile($fileName);        CreateFile($fileName,$count);    }     //创建文件    function CreateFile($fileName,$value)    {        $fp = fopen($fileName, "w+");        fwrite($fp, $value);        fclose($fp);    }     //删除文件    function DeleteFile($fileName)    {        @unlink($fileName);    }?>
Copy after login

测试了一下还是有效果的*^^*

最后,怎么可能告诉你..bae等云产品,以及da,cp面板都是支持cron的..

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!