mmarif4u Posted June 20, 2008 Share Posted June 20, 2008 Hi to all. I prepare a script b4 for cpanel to run by cron,was success.but that was a shared server. I want to run a php file through crontab. I know some basic things about cron.but need some more details. I have a dedicated server for one of my client running Debian on it. I want to run a php script where it will update some database tables in a 10 or 5 min interval of time. the best bet here is to run that script through crontab. i know it will be something like this: 10 * * * * /usr/local/bin/php /var/www/html/cron.php but now how could i setup this cron file to run properly. And is the above command is right and will work. how to run cron under a normal user,mean to create a file like cron.allow OR cron.deny Any details will be appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/111067-setting-up-cron-to-run-php-files/ Share on other sites More sharing options...
Stephen Posted June 20, 2008 Share Posted June 20, 2008 Taken from http://www.unix.com/unix-dummies-questions-answers/37379-using-php-script-crontab-noob.html What about this (adjust path to php executable below)? 30 * * * * /usr/bin/php /home/www/inc/crontab.php Note that your host may not necessarily have the php executable installed if it is just meant to run as a module to Apache. Only you (or your host admin) will know how the PHP is configured. In that case, you will not be able to run PHP scripts on the command line. By the way the following works for me: a.php: #!/usr/bin/php <?php phpinfo() ?> chmod +x a.php ./a.php So you probably may do it too. Link to comment https://forums.phpfreaks.com/topic/111067-setting-up-cron-to-run-php-files/#findComment-569948 Share on other sites More sharing options...
mmarif4u Posted June 20, 2008 Author Share Posted June 20, 2008 thanks for reply. i setup all these already in my script. <?php #!/usr/bin/php $dbhost = 'localhost'; $dbuser = '5446'; $dbpass = '1123'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = '123456'; mysql_select_db($dbname); $value=rand(100000,999999); $time=date('Y-m-d H:i:s'); $sql="insert into cron(time,value) values('$time','$value')"; $q=mysql_query($sql) or die (mysql_error()); echo $sql; ?> but i didnot get any new value in table. it mean there is problem either in the command OR the cron is not running. Link to comment https://forums.phpfreaks.com/topic/111067-setting-up-cron-to-run-php-files/#findComment-569957 Share on other sites More sharing options...
Stephen Posted June 20, 2008 Share Posted June 20, 2008 Well even if cron didn't work it should still insert. Find: $sql="insert into cron(time,value) values('$time','$value')"; Replace: $sql="INSERT INTO cron VALUES('$time','$value')"; Make sure cron is the correct table. Link to comment https://forums.phpfreaks.com/topic/111067-setting-up-cron-to-run-php-files/#findComment-569959 Share on other sites More sharing options...
mmarif4u Posted June 20, 2008 Author Share Posted June 20, 2008 Cron is correct table and i run cron.php file in browser ,working fine. Link to comment https://forums.phpfreaks.com/topic/111067-setting-up-cron-to-run-php-files/#findComment-569962 Share on other sites More sharing options...
bluejay002 Posted June 20, 2008 Share Posted June 20, 2008 can you describe more about the script you are trying to execute? can you post the code? Link to comment https://forums.phpfreaks.com/topic/111067-setting-up-cron-to-run-php-files/#findComment-569974 Share on other sites More sharing options...
mmarif4u Posted June 20, 2008 Author Share Posted June 20, 2008 The script is a test to setup crontab. which i already post above. later when it runs i will add more crons to it. Link to comment https://forums.phpfreaks.com/topic/111067-setting-up-cron-to-run-php-files/#findComment-569978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.