Jump to content

setting up cron to run php files


mmarif4u

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.