• <bdo id='w2Y44'></bdo><ul id='w2Y44'></ul>
      <legend id='w2Y44'><style id='w2Y44'><dir id='w2Y44'><q id='w2Y44'></q></dir></style></legend>

      <small id='w2Y44'></small><noframes id='w2Y44'>

        <i id='w2Y44'><tr id='w2Y44'><dt id='w2Y44'><q id='w2Y44'><span id='w2Y44'><b id='w2Y44'><form id='w2Y44'><ins id='w2Y44'></ins><ul id='w2Y44'></ul><sub id='w2Y44'></sub></form><legend id='w2Y44'></legend><bdo id='w2Y44'><pre id='w2Y44'><center id='w2Y44'></center></pre></bdo></b><th id='w2Y44'></th></span></q></dt></tr></i><div id='w2Y44'><tfoot id='w2Y44'></tfoot><dl id='w2Y44'><fieldset id='w2Y44'></fieldset></dl></div>
      1. <tfoot id='w2Y44'></tfoot>
      2. 调度php脚本

        Scheduling php scripts(调度php脚本)
        <i id='8NHh4'><tr id='8NHh4'><dt id='8NHh4'><q id='8NHh4'><span id='8NHh4'><b id='8NHh4'><form id='8NHh4'><ins id='8NHh4'></ins><ul id='8NHh4'></ul><sub id='8NHh4'></sub></form><legend id='8NHh4'></legend><bdo id='8NHh4'><pre id='8NHh4'><center id='8NHh4'></center></pre></bdo></b><th id='8NHh4'></th></span></q></dt></tr></i><div id='8NHh4'><tfoot id='8NHh4'></tfoot><dl id='8NHh4'><fieldset id='8NHh4'></fieldset></dl></div>
        <legend id='8NHh4'><style id='8NHh4'><dir id='8NHh4'><q id='8NHh4'></q></dir></style></legend>
          <tbody id='8NHh4'></tbody>
        • <bdo id='8NHh4'></bdo><ul id='8NHh4'></ul>

          <small id='8NHh4'></small><noframes id='8NHh4'>

        • <tfoot id='8NHh4'></tfoot>
                  本文介绍了调度php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想创建一些函数来安排 php 脚本,例如,如果我想在 12/12/2012 12:12 运行 page.php,我可以调用

                  I want to create some function to schedule php scripts,for example if i want tu run page.php at 12/12/2012 12:12 i can call

                  schedule_script('12/12/2012 12:12','page.php');//or by passing a time/datetime object
                  

                  或者例如每分钟调用一个脚本

                  or for example call one script every minute

                  schedule_interval(60,'page.php');//every 60s=1minute
                  

                  我可能会添加一些其他功能来查看调度了哪些脚本或删除其中一个.

                  i'll may add some other function to see what script are scheduled or delete one of them.

                  我希望这个功能在 UNIX 和 WINDOWS 平台上都能工作,我不想要丑陋的解决方案,比如在网站的每个页面上执行脚本(我想在没有人在网站上时安排这个命令)或使用buisy等待"的实现(在脚本上使用 sleep() 来检查是否有任何计划的作业)或需要用户干预的东西(例如在控制台中写入内容或打开面板).

                  i want this functions to work on both UNIX and WINDOWS platforms,i DO NOT want ugly solutions like executing a script on every page of the site(i want to schedule this commands when nobody is on the site) or using "buisy wait" implementations ( using sleep() on a script that checks if there are any scheduled jobs) or something that require user intervention(like write something in console or open a panel).

                  我在 MSDOS 上发现了AT"命令(在所有 Windows 上运行良好)但它非常基础,因为它只接受时间而不接受日期,UNIX 上有一个更强大的版本,但我不知道如何使用它(我想要一个适用于两个平台的解决方案).

                  I found the "AT" command on MSDOS(works well on all windows)but it's very basic because it accept only time and not dates,there's a more powerful version on UNIX but i don't know how to use it(and i want a solution for both platforms).

                  推荐答案

                  有一个 PHP 函数可以让您将脚本执行延迟到某个时间点.

                  There's a PHP function which lets you delay script execution till a point in time.

                  假设我有 cron.php:

                  <?php
                  
                     // Usage:
                     //    cron.php [interval|schedule] [script] [interval|stamp]
                     if(!isset($argc) || count($argc)!=2)die; // security precaution
                  
                     $time=(int)$argv[3]; // just in case :)
                  
                     if($argv[1]=='schedule'){
                         time_sleep_until((int)$_GET['until']);
                         include_once($time);
                     }elseif($argv[1]=='interval')
                         while(true){ // this is actually an infinite loop (you didn't ask for an "until" date? can be arranged tho)
                             usleep($time*1000); // earlier I said milliseconds: 1000msec is 1s, but this func is for microseconds: 1s = 1000000us
                             include_once($argv[2]);
                         }
                  
                  ?>
                  

                  还有你的 classes/functions 文件:

                  // Const form K2F - Are we on windows?
                  define('ISWIN', strpos(strtolower(php_uname()),'win')!==false &&
                                  strpos(strtolower(php_uname()),'darwin')===false );
                  
                  // Function from K2F - runs a shell command without waiting (works on all OSes)
                  function run($cmd){
                      ISWIN ? pclose(popen('start /B '.$cmd,'r')) : exec($cmd.' > /dev/null &');
                  }
                  
                  script_schedule($script,$time){
                      if(is_string($time))$time=strtotime($time);
                      run('php -f -- schedule '.escapeshellarg($script).' '.$time);
                  }
                  
                  script_interval($script,$mseconds){
                      run('php -f -- interval '.escapeshellarg($script).' '.$mseconds);
                  }
                  

                  它应该可以工作.顺便说一下,K2F 是这个框架,可以让你的梦想成真......更快.;)干杯.

                  It ought to work. By the way, K2F is this framework that makes your dreams come true..faster. ;). Cheers.

                  如果您仍然需要有关计算正在运行的作业和/或删除(停止)它们的部分,我也可以帮助您解决.只需回复我的帖子,我们就会跟进.

                  If you still want the parts about counting running jobs and/or deleting(stopping) them, I can help you out with it as well. Just reply to my post and we'll follow up.

                  这篇关于调度php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

                  <small id='Lqwxt'></small><noframes id='Lqwxt'>

                    • <i id='Lqwxt'><tr id='Lqwxt'><dt id='Lqwxt'><q id='Lqwxt'><span id='Lqwxt'><b id='Lqwxt'><form id='Lqwxt'><ins id='Lqwxt'></ins><ul id='Lqwxt'></ul><sub id='Lqwxt'></sub></form><legend id='Lqwxt'></legend><bdo id='Lqwxt'><pre id='Lqwxt'><center id='Lqwxt'></center></pre></bdo></b><th id='Lqwxt'></th></span></q></dt></tr></i><div id='Lqwxt'><tfoot id='Lqwxt'></tfoot><dl id='Lqwxt'><fieldset id='Lqwxt'></fieldset></dl></div>

                        <bdo id='Lqwxt'></bdo><ul id='Lqwxt'></ul>

                          • <legend id='Lqwxt'><style id='Lqwxt'><dir id='Lqwxt'><q id='Lqwxt'></q></dir></style></legend>
                          • <tfoot id='Lqwxt'></tfoot>
                              <tbody id='Lqwxt'></tbody>