Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中作为守护进程执行脚本_Php_Bash - Fatal编程技术网

在PHP中作为守护进程执行脚本

在PHP中作为守护进程执行脚本,php,bash,Php,Bash,我的php页面javascript中的此脚本在页面加载时调用: <script type="text/javascript"> var id =0; function getData(){ $.ajax({ url : "refresh.php", type : "POST", data : {"id" : id}

我的php页面javascript中的此脚本在页面加载时调用:

<script type="text/javascript">
        var id =0;
        function getData(){    
        $.ajax({
              url       : "refresh.php",
              type      : "POST",
              data      : {"id" : id},            
              success   : function(data) {
                 $(".show").html(data);
              }
          });
    }
        $(document).ready(function(){
      setInterval("getData()",36000);//Polls in every x sec
    });
    </script>   
?>

我已经看到了
在后台执行php脚本的所有结果

其中显示的解决方案如下:

  • nohup php myscript.php&

    但是诺胡普有一些问题

  • 2.
    exec(“/bin/bash-c'/usr/bin/php/path/to/child.php 2>/dev/null'&”)

    及其他


    我很困惑。哪种方法是正确的?

    如果希望脚本每小时自动执行一次,可能需要研究cron。大多数web主机至少通过其控制面板提供cron服务。

    如果您在linux上,请使用
    crontab-e
    然后每小时输入一次

    0****/bin/php/your_path/refresh.php

    <?php
        error_reporting(E_ERROR | E_PARSE);
        $feedUrl = "http://api.frrole.com/v1/curated-content?location=India&contenttype=link&orderby=popularity&apikey=wmqmz15svzH8qSy5yQuF52b068a40a69e";
        $json = file_get_contents($feedUrl);
        $code = json_decode($json,true);
    
        foreach($code as $arr)
        {
        foreach($arr as $k=>$v)
        {
        echo $arr[$k]['title']."<br>";
        echo $arr[$k]['city']."<br>";
        //inserts this vvalue in db
        echo "<br>";
        }
        }
    
    然后保存文件

    :wq


    @查布里亚:如果允许进入手册,那么肯定不会有任何问题。我想要完全自动化