Cronjob only processing half

Desdinova

Verified User
Joined
Mar 14, 2006
Messages
56
Allright I have this PHP script which works fine when run from the browserwindow.

in the script there's a
$ping = shell_exec("ping -c 1 domain.com");

I want it to mail the $ping value to me. The mailer is not the problem.

just to see if the cronjob was started succesfully I put a mailcommand at the beginning of the script, mailing me that it has started. this message did arrive.

I think the error is at the shell_exec, since all the $ping-related processing is not executed, basically giving me the idea that $ping does not exist, thus the shell_exec was not run.

i think?
 
Just a few thoughts:

1. Have you tried exec instead of shell_exec?

2. Are you sure the ping executable is reachable from your php script? What if you add the full path to the ping executable in the exec command?

3. Have your tried inserting an echo after the exec command to display the value of $ping? Or if you can't see output from the script, insert an alert to display the value of $ping.

4. Maybe php is running in safe_mode on the server. If that is the case you can only execute commands in the safe_mode_exec_dir folder.
 
1. just tried exec and having it mail the $ping value to me. I receive the mail, just no $ping data seems to be set.

2. It is reachable through my script when I open it with my browser. How can I find the full path?

3. yes but I can't do that with the cronjob. If I add the echo $ping; line, and open it in my browser I see results.

4. So how should I handle that?
 
2. It is reachable through my script when I open it with my browser. How can I find the full path?
The location of the ping executable depends on the linux version you're using. Not all distro's have this command in the same location. The administrator of your server should be able to provide you with this information.

3. yes but I can't do that with the cronjob. If I add the echo $ping; line, and open it in my browser I see results.
Try writing the value of $ping to a file in your home directory? That way you can check the value after the cron job is finished.

4. So how should I handle that?
You would have to ask the administrator of your server to copy the ping executable to the safe_mode_exec_dir folder.

Have you tried any other command to see if it is related specifically to the ping command or that this problem occurs with any command you try? (you could try uptime, free, who etc. for example)

Also maybe suphp could be running on your server. If that's the case then you should make sure that your user account has sufficient rights to execute commands (ask your administrator).
 
Come to think of it, that last part couldn't be the cause of the problem since you're able to execute the command if you execute the script manually...

How exactly do you execute the script from a cron job?

And what 'user' is running the script if you run it as a cron job? That's about the only difference I can think of between running the script as a cron job or running the script manually. Well, that and possibly the current directory (pwd) when the script is executed.
 
Last edited:
I use this line:
(/usr/local/bin/php /home/(user)/domains/(domain)/public_html/services/ping.php

it's on freeBSD, and I'm admin :')
 
I'm afraid i can't help you much further, except maybe double-checking that access rights are in order. Everything else appears to be ok so i don't know why this doesn't work.

Maybe someone else here has an idea of what else you could try. Or you could ask in the phpfreaks forum (www.phpfreaks.com/forums). There are many php experts overthere.
 
Back
Top