cronjob to run a php script

royroes

Verified User
Joined
Mar 22, 2005
Messages
6
Hello,

I've written a php script that imports a xml-file in an mysql database. Now i want to run this script every hour.

I've tried the cronjob option in DirectAdmin, but I can't get it to work.

I would like to run the file:

/home/username/domains/mydomain.ext/public_html/new/importxml.php

All help is welcome.....

Greetz Roy
 
royroes said:
Hello,

I've written a php script that imports a xml-file in an mysql database. Now i want to run this script every hour.

I've tried the cronjob option in DirectAdmin, but I can't get it to work.

I would like to run the file:

/home/username/domains/mydomain.ext/public_html/new/importxml.php

All help is welcome.....

Greetz Roy

You need to specify that it should be run with the PHP interpreter. You command should look something like this...

Code:
/usr/bin/php /home/username/domains/mydomain.ext/public_html/new/importxml.php

Make sure you specify the full path to PHP.

Kind regards,
Onno Vrijburg
 
Don't you also have to add the export the output to /dev/null as well? I must admit I'm not to experienced with cron so I'm not totally sure myself.

-drmike
 
drmike said:
Don't you also have to add the export the output to /dev/null as well? I must admit I'm not to experienced with cron so I'm not totally sure myself.

-drmike

That would depend on your script but in general it should not matter if there is output however it is good practice to send output and errors to log files (or /dev/null) when you run the scripts in unattended mode (ie in a cronjob).

Regards,
Onno Vrijburg
 
The line:

/usr/bin/php /home/username/domains/mydomain.ext/public_html/new/importxml.php

doesn't work.

Greetz Roy
 
royroes said:
The line:

/usr/bin/php /home/username/domains/mydomain.ext/public_html/new/importxml.php

doesn't work.

Greetz Roy


Where is your PHP located?

Regards,
Onno Vrijburg
 
royroes said:
I don't know where can I see that info?

Greetz Roy

Log into your box (as root) using SSH.

# cd /
# locate php

Should give you several references to PHP you should look for /usr/....

You might also find it in the php.ini file (not sure of this)

Regards,
Onno Vrijburg
 
I've tried ssh and i get a very big list using 'locate php' command.

Could /usr/local/lib/php be a good path?

I don't think so, because when i tried this in the cronjob it didn;t work either.

Greetz Roy
 
royroes said:
I've tried ssh and i get a very big list using 'locate php' command.

Could /usr/local/lib/php be a good path?

I don't think so, because when i tried this in the cronjob it didn;t work either.

Greetz Roy

Here is a line that I have in my crontab that works...

Code:
/usr/local/bin/php -q -f /home/<user>/domains/<domainname>/public_html/script.php

as you can see the path (on RH9) is /usr/local/bin/php

Kind regards,
Onno Vrijburg
 
/usr/local/bin/php -q -f /home/<user>/domains/<domainname>/public_html/script.php

doesn't work either, must there be something in the php file to can be executed by a cronjob?

Greetz Roy
 
royroes said:
I've tried ssh and i get a very big list using 'locate php' command.

Um, may I suggest reading the list looking for something that says 'php' and only php. Might be quicker then guessing. :)

You might have to increase the number of lines that your ssh client saves in its history. I know putty only does 200.

-drmike
 
The problem here is access rights to the script. I exchanged a couple of PM's with Roy and at the end of the day he was not able to get to the script he wanted to execute with the user that was running the cronjob. I don't know if he solved the problem yet.

Regards,
Onno Vrijburg
 
The problem isn't solved at this moment.
Onno helped me a lot, but I don't know how to get more rights.....
The file to be executed has 777 rights......

Greetz Roy
 
Back
Top