FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Cron jobs and PHP?





Diablosblizz
Okay, I have NO idea how Cron Jobs work. I have this set up in my Cron Job page (DirectAdmin):

Minute: */5
Hour: *
Day of Month: *
Month: *
Day of Week: *
Command: php -q /home/diablosb/checkoff.php

checkoff.php has:
Code:
<?php
function pingDomain($domain){
    $starttime = microtime(true);
    $file      = fsockopen ($domain, 1232, $errno, $errstr, 5); // 80 = port, 5 = times
    $stoptime = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;  // Site is down
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 1000;
        $status = floor($status);
    }
    return $status;
}

$status = pingDomain("24.36.122.119"); // Change to your IP
if($status != -1) {
   mail("diablos_blizzard@hotmail.com", "Member-Ship Validation", "Server is online!", "From: Online / Offline");
   }else{
   mail("diablos_blizzard@hotmail.com", "Member-Ship Validation", "Server is offline!", "From: Online / Offline");
}
?>



The Cron is supposed to run every 5 minutes, and it is supposed to run the checkoff.php. The Cron Daeom sent me a email that said:

Quote:
/bin/sh: line 1: php: command not found



So, some questions are:

1. Is my Cron Job set up properly to run every 5 minutes? (If that is too soon then I can change it to 10 minutes, if that is okay)
2. Is the command URL correct?
3. Is there anything wrong with the script?

Many thanks!!!
Peterssidan
1. It's to often if you are using Frihost.
TOS wrote:
Any of the following is strictly not allowed, unless stated otherwise.
...
15. Cron jobs that are being executed more often than once per 15 minutes or generating a lot of cpu

I don't know the other answers.
Diablosblizz
Alright, I will redo the time.
MrBlueSky
A cronjob is starting in an 'empty environment', in which no PATH is set. So when you use 'php -q /home/diablosb/checkoff.php' as cronjob command, the shell (/bin/sh) has no idea were to find PHP.

Instead use something like this as command:

/usr/local/bin/php -q /home/diablosb/checkoff.php

(Assuming /usr/local/bin/php is the path of php, but I don't know where php is located at the frihost server)

--edit--

Yes, the path of php on frihost is /usr/local/bin, so this command should work.
Diablosblizz
EDIT: FIXED IT!
SlovenianBoy
Code:

<?
$file = '...';
$datei = fopen('time.txt', 'r+');
$time = fgets($datei, 20);
$time = $time + 86400;
$now = time();
If ($now >= $time){
    include ($file);
    rewind($datei);
    fputs($datei, $now);
}
fclose($datei);
?>



I found this php snippet good, if your host dont support cronjob, just replace '...'; with the file of your choice ,and include this code for example in index.php of your page, so 1 visit a day is enought to call the procedure.
Johntheviper
What about using cronjobs24.de? It's free and i think thats more easier than making a own script. Embarassed
Related topics
Cron Jobs
Cron Jobs
Cron jobs - running a php file
Executing automated tasks without using cron jobs
cron jobs?
Problems With Cron Jobs
Enabling Cron Jobs
Question: PHP scripting + cron jobs
CRON Jobs
how do cron jobs work?
Cron jobs on DirectAdmin
Cron jobs
Has anyone installed Moodle successfully?
[Urgent] Cron Jobs
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.