PHP Classes

How To Run PHP Cron Daemon

Recommend this page to a friend!

      PHP Cron Daemon  >  All threads  >  How To Run PHP Cron Daemon  >  (Un) Subscribe thread alerts  
Subject:How To Run PHP Cron Daemon
Summary:How do I set up PHP Cron Daemon and use it to call a php script
Messages:10
Author:Ian Philip
Date:2008-09-26 10:06:35
Update:2012-11-30 15:04:57
 

  1. How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of Ian Philip Ian Philip - 2008-09-26 10:06:41
I need to call a php script at regular intervals.

I have tried using (Unix) Cron Tabs, but this does not recognize php scripts.

I downloaded PHP Cron Daemon, but I cannot find any instructions.

1. How do I supply a user name and password for my SQL database to PHP Cron Daemon?

2. How do I schedule and call a php script (e.g. example.php)?

  2. Re: How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of Mark Wigglesworth Mark Wigglesworth - 2010-02-18 10:28:33 - In reply to message 1 from Ian Philip
I wish I knew, I have no idea how to run this. Seriously anyone?

  3. Re: How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of Maxime Martineau Maxime Martineau - 2010-12-14 18:11:04 - In reply to message 2 from Mark Wigglesworth
I have installed this library over Ubuntu 10.04.1 using PHP 5.3.2.

I simply unzipped the package and put the access to my db(mysql) into daemon.php.

you have to replace these lines :

define ('DB_HOST', 'localhost');
define ('DB_USER', 'username');
define ('DB_PASS', 'password');
define ('DB_NAME', 'crontab');

You will aslso have to create a new database named crontab and import the content of the db.sql.

I had to fix 2 files so it works :
daemon.php line 63 add : global $debug;
lib/cron/daemon.php line 127 add : global $db;

then i just run in command line :
php daemon.php

and it just start itself normally. I didn't had the time test it fully yet.


For windows user : the "ftok" fucntion does not exist in windows and no package that include it either. I tried a solution of having a replacement for that function, but it just didn't worked at all.(program crashed without any notice)


Hope this help someone !!

  4. Re: How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of Maxime Martineau Maxime Martineau - 2010-12-14 20:50:53 - In reply to message 3 from Maxime Martineau
finally, i tested it more and was able to "bug fix" error that was remaining in the code.

I discover that you need to fill the table "crontab" like this :

INSERT INTO `crontab` (
`id`,
`title`,
`description`,
`code`,
`concurrent`,
`implementationId`,
`cronDefinition`,
`lastActualTimestamp`)
VALUES
(
2,
'first test',
'first test using this thing and php',
'system("php /test.php");',
0,
1,
'* * * * *',
0);

i may be wrong, but i seems to noticed this :

implementationId is used to identify on which environnement the process is gonna run in case of concurrency. Concurrency is not permitted if the same process is not in the same environnement.

concurrent is the number of concurrent process of the same job can be there


I have put the fixed code to a web link cause i didn't know how to do it here.

Here is the link :
myfreefilehosting.com/f/922681796b_ ...

complete package, unzip and ready to use ^^

  5. Re: How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of Denis Collis Denis Collis - 2011-02-27 16:44:47 - In reply to message 1 from Ian Philip
If you want to use a Unix-like crontab entry to run php scripts, you must use a command line web browser like wget. Then you simply insert the command into the crontab in the usual way, example:

# crontab
# =======
#
# backup database at 4:30am
30 4 * * * wget -q -O /dev/null http://www.mydomain.com/maint/DB_Backup.php

  6. Re: How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of Denis Collis Denis Collis - 2011-02-27 17:08:34 - In reply to message 5 from Denis Collis
Of course, notwithstanding my response above, the whole point of the "PHP Cron Daemon" is to manage a job schedule where access to the system cron is either:

1) impractical - you want to control it via the web

- or -

2) impossible - your hosting service disallows access to the system cron

  7. Re: How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of Anthony Riches Anthony Riches - 2012-05-26 14:42:30 - In reply to message 6 from Denis Collis
Also tried to Install Cron Daemon, but get the following error :-

SQL-Befehl:

CREATETABLEIFNOTEXISTS`cronJob` (

`id` int( 11)NOTNULLAUTO_INCREMENTCOMMENT'unique identifier',
`crontabId` int( 11)NOTNULL default'0',
`startTimestamp` timestamp NOTNULLCOMMENT'start',
`endTimestamp` timestamp NOTNULL default'0000-00-00 00:00:00' COMMENT'end of run',
`code` longtext NOTNULLCOMMENT'PHP code to be executed',
`concurrent` tinyint( 4)NOTNULL default'0' COMMENT'handles concurrency',
`implementationId` int( 11)NOTNULL ,
`results` longtext NOTNULLCOMMENT'output of script',
`pid` int( 11)NOTNULL default'0',
PRIMARYKEY (`id`) ,
KEY`startTimestamp` (`startTimestamp`) ,
KEY`crontabId` (`crontabId`) ,

) TYPE=InnoDB AUTO_INCREMENT=1;



MySQL meldet:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') TYPE=InnoDB AUTO_INCREMENT=1' at line 14


Could anyone help me with this please ?

  8. Re: How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of mad max mad max - 2012-06-11 13:57:53 - In reply to message 7 from Anthony Riches
Remove TYPE=InnoDB from your SQL statement

  9. Re: How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of mad max mad max - 2012-06-11 14:01:03 - In reply to message 7 from Anthony Riches
Also remove the last comma on the line with: 'KEY`crontabId` (`crontabId`) ,'... it should read 'KEY`crontabId` (`crontabId`)' (ignore single quotes; they're for ease of reading)


  10. Re: How To Run PHP Cron Daemon   Reply   Report abuse  
Picture of SCC scc SCC scc - 2012-11-30 15:04:57 - In reply to message 3 from Maxime Martineau
please, can you send me your last code?
I'm having several problems in executing in linux server with Mysql 5.5 and php 5.3.

thanks.

Susana