Jump to content

PHP script to be run by CRON


Tjk

Recommended Posts

I've got CRON set up to run this file below every minute... (this is the entire contents of the file)

[code=php:0]
<?php
$to= "myemail@emailprovider.com";
$subject= "cron test";
$message= "if you receive this cron is working!";
mail($to, $subject, $message);
?>
[/code]

Am I missing something about running PHP scripts using CRON or is it a server configuration problem?

Help appreciated as always.
-Tjk
Link to comment
Share on other sites

Set the cronjob to write to file instead. That will tell you if the problem is with mail config or cronjobs.

Example:
[code]<?php
setlocale(LC_TIME, "NL_nl");
$time = strftime("%H:%M:%S");
$fp = fopen('test.txt','w');
fwrite($fp,'time: '.$time."\n");
?>[/code]

Check file afterwards. If everything is as expected, evaluate your mail settings.
Link to comment
Share on other sites

Out of interest, if I load the script through my web browser should I see a blank page or should I get the error I'm getting which says "Warning: fopen(test.txt): failed to open stream: Permission denied"?

Also, I tried it with CRON with no luck.
Link to comment
Share on other sites

since CRON jobs are not run from a browser, the server doesn't always know what to use to parse the code.  try adding this:

[code]#!/usr/bin/php -q[/code]

to the top of your script (before the opening PHP tag); this line tells the server (linux i believe for this line) what to use to parse the code and where it's located.  i don't often use command line, so someone can probably correct my terminology, but this is what i need to add to my CRONs usually.
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.