1

I would like to set a cron job in cpanel to run these different pages. I thought it would be easier to put them in one file. I know how to set these up to run individually, but the way it is written below, it won't run.

What do I need to change to get it to run smoothly?

<?php
 ini_set('max_execution_time', 18000);
 exec('/usr/bin/php -q /home2/sample/public_html/linktest/myapp-page1.php');  
sleep (120);
 exec('/usr/bin/php -q /home2/sample/public_html/linktest/myapp-page2.php');  
sleep (120);
 exec('/usr/bin/php -q /home2/sample/public_html/linktest/myapp-page3.php');  
sleep (120);
 exec('/usr/bin/php -q /home2/sample/public_html/linktest/myapp-page4.php');  
sleep (120);
 exec('/usr/bin/php -q /home2/sample/public_html/linktest/myapp-page5.php');  
sleep (120);
echo 'Cron ran successfully';
?>

Thanks!

skaffman
  • 398,947
  • 96
  • 818
  • 769
user732424
  • 11
  • 2

4 Answers4

0

you can use this technique it will help to call as many as pages you like all pages will run at once independently without waiting for each page response as asynchronous.

cornjobpage.php //mainpage

    <?php

post_async("http://localhost/projectname/testpage.php", "Keywordname=testValue");
//post_async("http://localhost/projectname/testpage.php", "Keywordname=testValue2");
//post_async("http://localhost/projectname/otherpage.php", "Keywordname=anyValue");
//call as many as pages you like all pages will run at once independently without waiting for each page response as asynchronous.
            ?>
            <?php

            /*
             * Executes a PHP page asynchronously so the current page does not have to wait for it to     finish running.
             *  
             */
            function post_async($url,$params)
            {

                $post_string = $params;

                $parts=parse_url($url);

                $fp = fsockopen($parts['host'],
                    isset($parts['port'])?$parts['port']:80,
                    $errno, $errstr, 30);

                $out = "GET ".$parts['path']."?$post_string"." HTTP/1.1\r\n";//you can use POST instead of GET if you like
                $out.= "Host: ".$parts['host']."\r\n";
                $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
                $out.= "Content-Length: ".strlen($post_string)."\r\n";
                $out.= "Connection: Close\r\n\r\n";
                fwrite($fp, $out);
                fclose($fp);
            }
            ?>

testpage.php

    <?
    echo $_REQUEST["Keywordname"];//case1 Output > testValue
    ?>

PS:if you want to send url parameters as loop then follow this answer :https://stackoverflow.com/a/41225209/6295712

Community
  • 1
  • 1
Hassan Saeed
  • 6,326
  • 1
  • 39
  • 37
0

Or you could use wget and load a set of URLs from a file

wget -i CronScripts.txt

These would have to be accessible from the outside world though

Adam Casey
  • 1,600
  • 12
  • 21
0

Is it possible you are running in safe_mode and not allowed to modify max_execution_time?

Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83
-1

you need to make sure that the exec function is allowed in your php.

Vish
  • 4,508
  • 10
  • 42
  • 74
  • Exec is always allowed; the restriction for safe mode is that you might only be able to run scripts in the safe_mode_exec dir. But if safe mod is on, they can't modify max_execution_time. – Scott C Wilson Apr 30 '11 at 16:41