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= "[email protected]";
$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
https://forums.phpfreaks.com/topic/17548-php-script-to-be-run-by-cron/
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.
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.