bash - Executing script as daemon process in PHP


This script in my php page javascript which is called on page load:

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

refresh.php does my actual process, which I want to get executed every 1 hour

What is the way so thatrefresh.php get executed autmatically at everyone hour?


    error_reporting(E_ERROR | E_PARSE);
    $feedUrl = "";
    $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>";


I have seen all result ofexecute php script in background om Google

which show solution like this:

  1. nohup php myscript.php &

    but nohup has some issues

  2. 2.

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

and other

I am confused. Which one is correct way to do this?




If you want a script to execute automatically every hour, you might want to investigate cron. Most web hosts offer cron services through their control panel at least.




usecrontab -e if you are on linux then enter this for every hour

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

then save the file


People are also looking for solutions to the problem: php - To load controller using codeigniter


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.