Cron jobs for php scripts..

Status
Not open for further replies.

Hanan

Verified User
Joined
Aug 10, 2007
Messages
12
Hey guys,
wonder why when I adding new cron for php file he didn't run it...
I did all the possibility phrases...

can someone please tell me or give me example to run php file...

what I did:
php /home/....
php -f /home/....
/usr/local/bin/php /home/...

and it's not working to me..

Cheers.
 
This should work fine:

Code:
/usr/local/bin/php -q /home/user/domains/domain.com/public_html/script.php

Maybe you have a problem with your script, check crond logs in /var/log directory.
 
I had a problem and your piece of quote has solved it. I simply was trying to run my script without /usr/local/bin/php -q. Now it works fine.

Thank you.
 
I've added above line to my script and I changed command to :
/usr/bin/php -q/home/***/domains/***/public_html/cron/temp.php
but still it doesn't work, can you help me please?
here is a simple php code I've used to test my cron jobs:
<?php
#!/usr/local/bin/php
$f='test.txt';
$p=fopen($f,'w');
fwrite($p,'kaytan');
fclose($p);
?>
can you help me please?
 
Last edited:
It should be:
Code:
cd /home/user/domains/domain.com/public_html; /usr/local/bin/php -f script.php
By the way, the -q switch doesn't do anything.
 
It should be:
Code:
cd /home/user/domains/domain.com/public_html; /usr/local/bin/php -f script.php
By the way, the -q switch doesn't do anything.

You are the master tillo. I tried all possible options. Even from the provider wiki it did not work. This command works fine. Thank you!
 
Im Having Issues with my cronjobs as well,

My php script is working fine, but when i set the time to run the script it does not run the php scripts... any ideas??

/usr/local/bin/php /home/admin/public_html/cron/auto_time.php

Thank you!
 
no, I just check the the cron log and it did not ran. do i have give the file any special of permission??
 
If there's no any records for this task in your crontab's logs, then your cron either is not working properly or not logging anything.
 
The issue was that the cron doesnt like when you include function in your code like 'include ("../public_html/functions/function.php");' ...

I removed the functions and then it work fine!

Thank you for your Help!!
 
Thats why you would have to change directories first to get it to work that way.

cd /path/to/folder; /usr/bin/php script.php
 
The issue was that the cron doesnt like when you include function in your code like 'include ("../public_html/functions/function.php");' ...

I removed the functions and then it work fine!

Thank you for your Help!!

The solution was suggested in Post#9
 
Apparently none of these solutions will solve my problem whitch is similar. Sorry if I better started a new thread.

What I want to do:
I have a php file running a script that parses an external xml file an inserts the data in the database. I want to run this script every (let's say) 10 minutes using a corncob.

I have a rented VPS server running DirectAdmin, PHP 5.2.13, ZendEngine2 and Server API: Apache 2.0 Handler (I read somewhere this is important when using cron jobs)

For a time interval of every 10 minutes I use : */10 * * * * and I'm assuming this is right
The pathname to my php file is changed in this post but even my hosting company stated that I had that right also. And the permissions should also be ok.

Searching for an working line I tried
/usr/local/bin/php -q /home/user/domains/mydomain.com/directory/file.php
/home/user/domains/mydomain.com/public_html/directory/file.php
/usr/local/bin/php /home/user/domains/mydomain.com/public_html/directory/file.php
/usr/local/bin/php -q /home/user/domains/mydomain.com/public_html/directory/file.php
/usr/local/bin/php -f /home/user/domains/mydomain.com/public_html/directory/file.php
/usr/local/bin/php -f http://www.mydomain.com/directory/file.php
cd /home/user/domains/mydomain.com/public_html/directory; /usr/local/bin/php -f file.php
/usr/local/bin/wget -o /dev/null -q http://www.mydomain.com/directory/file.php
lynx -dump http://www.mydomain.com/directory/file.php
root /usr/bin/wget -O /dev/null http://www.mydomain.com/directory/file.php
wget -O /dev/null –q http://www.mydomain.com/directory/file.php

And some more slight variation I forgot to keep (with or without -q -f).

None of my efforts do anything. I don't get any mail and nothing is written in the Cron log file.

I talked to one of the people from my hosting company and he said "wget -O /dev/null –q" works for there website but since he's not a programmer he could not help me. He assured me everything was ok with the server and corncobs was on and working. He thinks there is something wrong with the file I want to trigger but when I run it in a browser it works. Do I need to ad script to the file if I want to run it with a cron job?

Can someone please push me in the right direction?

Thanks
 
/usr/local/bin/php /home/user/domains/mydomain.com/public_html/directory/file.php

this should be the right one, BUT, should be important to know if PHP is as CLI or CGI.

Cause in CLI version the php path is the one in the line i wrote up here while in CGI version the php binary file have another path.

By the way, if you run that command line directly, does it work?

Also, try php -v and whereis php to check the right php binary file path.

Regards
 
@kwindo,

Is your file encoded? Or is it allowed to be accessed from only a certain IP via http?

Anyway send me a PM, I'll check it out for a nominal charge.
 
Thanks very mush for your replies. Sorry if I seem an amateur but basically I am and I'm trying to learn as mush as I can.

@SeLLeRoNe: I've been trying to figure out the CLI, CGI part. If found following text on this page: http://www.htmlcenter.com/blog/running-php-scripts-with-cron/

You will need to find out the answer to the following question, “Is my PHP installed as CGI or as an Apache module?”. To find out do the following: Create a new file, name it info.php (just an example), and put in the following code, “<? phpinfo(); ?>”. Upload to your webserver and go to it with your browser.

Now check for Server API (4th item from the top), if it says “CGI”, you have PHP compiled as CGI, if it reads “Apache”, you have it running as an Apache module.

If I do that I find "Apache 2.0 Handler" under "Server API". According to the text above PHP is installed as an Apache module and not CGI. (I don't know if thats the same as CLI).

However: I have a Joomla site running on that domain and when I check the larger PHP info page in the admin I can not find any reference to CLI but "mod_cgi" at "Loaded Modules" and "CGI/1.1" at "GATEWAY_INTERFACE".

As for command line, I logged in once on my server using the console on my Mac so I should be able to do that again. Other then that I don't really know what I am doing so it seems unwise to just start sending commando's.

@zEitEr: The file is one I wrote myself, it's just a php file running a script to parse an external xml file and insert the data to the database. A real programmer will probably turn green when seeing my code but it works perfectly when I trigger it with a browser. Other then it's basic functions there is no code and I just dropped it on the server over ftp.

Thanks for your offer. If you don't mind I want to try and figure this out and maybe understand why it doesn't work. After all I need to get this running some day so I might come back to you on that offer.

Could it be I need to ad some code to the php file? I have a gut feeling it's something with the file and not the corncob.
 
if is as cgi so is the php path prolly.

Had you tried to run the command in ssh? does it work?

for understand if you are using cgi or cli please post the result of

Code:
cat /usr/local/directadmin/custombuild/options.conf | grep php

So this will solve any doubt.

and please provide the output of

Code:
whereis php

and

Code:
php -v

Regards
 
Status
Not open for further replies.
Back
Top