1fy07h 发表于 2024-10-4 14:15:37

PHP脚本执行按时任务的流程实例


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">php脚本执行<span style="color: black;">按时</span>任务的流程</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">1:swoole框架tick一个<span style="color: black;">按时</span>任务</h1>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">2:shell脚本来操作操作这个任务的<span style="color: black;">起步</span>,暂停,关闭,伪代码:sh shell文件</h1>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">3:web中利用PHP来执行shell命令</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">全部</span>闭环形成,<span style="color: black;">能够</span>在php<span style="color: black;">研发</span>的b/s架构中<span style="color: black;">运用</span>,是不是总结得很简单!</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面附上测试代码</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP<span style="color: black;">按时</span>任务代码脚本文件</p><span style="color: black;"><span style="color: black;">&lt;?php</span>

      \Swoole\Timer::tick(<span style="color: black;">3000</span>, <span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">(int $timer_id, $param1, $param2)</span> </span>{
      <span style="color: black;">echo</span> <span style="color: black;">"timer_id #$timer_id, after 3000ms.\n"</span>;
      <span style="color: black;">echo</span> <span style="color: black;">"param1 is $param1, param2 is $param2.\n"</span>;

      Swoole\Timer::tick(<span style="color: black;">14000</span>, <span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">($timer_id)</span> </span>{
      <span style="color: black;">echo</span> <span style="color: black;">"timer_id #$timer_id, after 14000ms.\n"</span>;
      });
      }, <span style="color: black;">"A"</span>, <span style="color: black;">"B"</span>);</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Shell脚本执行PHP<span style="color: black;">按时</span>任务脚本文件</p><span style="color: black;">#!/bin/sh</span>
    <span style="color: black;"># echo "直接时间<span style="color: black;">起始</span>============`date +%F %T`==========="</span>

    <span style="color: black;"><span style="color: black;">start</span></span>() {

    <span style="color: black;">echo</span> <span style="color: black;">"============<span style="color: black;">起步</span>成功==========="</span>
    }
    <span style="color: black;"><span style="color: black;">stop</span></span>() {

    <span style="color: black;">echo</span> <span style="color: black;">"============停止成功==========="</span>
    }
    <span style="color: black;"><span style="color: black;">restart</span></span>() {

    <span style="color: black;">echo</span> <span style="color: black;">"============重启成功==========="</span>
    }

    <span style="color: black;">echo</span> -e <span style="color: black;">"===========服务<span style="color: black;">起步</span>命令============ \n \n"</span>
    <span style="color: black;">echo</span> -e <span style="color: black;">"1:<span style="color: black;">起步</span>服务 2:停止服务 3:重启服务 0:取消 \n \n"</span>
    <span style="color: black;">echo</span> -e <span style="color: black;">"=================================== \n \n"</span>
    <span style="color: black;">read</span> -p <span style="color: black;">"请输入命令编号:"</span> inputText <span style="color: black;">#提示用户输入数字</span>
    <span style="color: black;">if</span> [ <span style="color: black;">$inputText</span> == 1 ]; <span style="color: black;">then</span>
    start
    <span style="color: black;">elif</span> [ <span style="color: black;">$inputText</span> == 2 ]; <span style="color: black;">then</span>
    stop
    <span style="color: black;">elif</span> [ <span style="color: black;">$inputText</span>== 3 ];<span style="color: black;">then</span>
    restart
    <span style="color: black;">elif</span> [ <span style="color: black;">$inputText</span> == 0 ]; <span style="color: black;">then</span>
    <span style="color: black;">echo</span> -e <span style="color: black;">"\n取消操作\n"</span>
    <span style="color: black;">fi</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP执行shell脚本文件</p>&lt;?<span style="color: black;">php
      <span style="color: black;">system</span>(<span style="color: black;"><span style="color: black;">sh py.sh</span></span>)</span>; <span style="color: black;">// 执行shell命令</span>




qzmjef 发表于 2024-10-8 15:40:55

外贸论坛是我们的,责任是我们的,荣誉是我们的,成就是我们的,辉煌是我们的。

j8typz 发表于 2024-10-12 20:17:02

软文发布论坛开幕式圆满成功。 http://www.fok120.com

b1gc8v 发表于 2024-10-17 02:56:37

认真阅读了楼主的帖子,非常有益。

m5k1umn 发表于 2024-10-19 16:36:48

外贸B2B平台有哪些?

nykek5i 发表于 2024-11-11 09:33:16

“NB”(牛×的缩写,表示叹为观止)‌
页: [1]
查看完整版本: PHP脚本执行按时任务的流程实例