自動運行php檔案

來源:互聯網
上載者:User
這篇文章主要介紹了PHP檔案的自動運行方法,分析了兩種自動重新整理的方法及相應的優缺點,需要的朋友可以參考下

本文執行個體分析了PHP檔案的自動運行方法。分享給大家供大家參考,具體如下:

這裡分析兩種方法:

第一種方法:

a.php檔案內容 如下:

<?php  ini_set("error_log", "c:\php\php_error.log");  error_log("a.php is execute----------",0);  ignore_user_abort(); // 後台無阻斷運行  set_time_limit(0); // 一直給我運行  $zhoz_execute_time = 30; // 已耗用時間seconds,這裡設定成一分鐘跑一次。  do {   // 這裡想執行什麼都可以寫了   error_log("a is do !!!!----------",0);   sleep($zhoz_execute_time); // 按指定軌道時間運行  } while (true); ?>

但這裡有個缺點,需要先運行一下這個PHP檔案,如通過url運行:http://www.php.cn/

這裡只要執行一次就可以了,然後關閉頁面。

另外,當Apache/IIS重啟後,這個指令碼就不會執行了。

為此,我又想到了另外一個方法:

在cmd下運行:

php-win.exe -c "c:\php\php.ini" -f C:\Apache2.2\htdocs\a.php

(這裡也只要運行一次,運行多了時間會縮短啟動並執行。)

這樣的話,即使怎麼重啟Apache/IIS這個指令碼仍然會啟動並執行。
還有缺點:重啟機器或殺死進程php-win.exe,當然它就不能跑了……
這個解決辦法,可以添加啟動項裡作成bat應該是可以完美解決!

第二種方法:

b.php內容:

<?php  $fp=fopen("c:\\test\\a.txt","a+");  fwrite($fp,"測試\r\n");  fclose($fp);?>

然後寫一個bat檔案,在其中寫入:

c:\php\php -c c:\php\php.ini -f c:\Apache2.2\htdocs\b.php

儲存

然後使用那個at 命令將其加入的計劃任務中

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.