0

I want to use cron with 2 php scripts.

When I run these scripts manually with php /soncourt/index.php (for example) on my destination server, it works, but when I want to use CRON it fails

First cron :

*/15 * * * * /maquette/index.php >> /maquette/index.log 2>> index.err

Second cron :

*/15 * * * * /soncourt/index.php >> /soncourt/index.log 2>> index.err

Here's the first script:

<?php
///////////////////////////////////////////// Preparation \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Recuperation des valeurs obligatoires
//Preparation de la DATE
date_default_timezone_set('Europe/Paris'); // Mise a la bonne heure (Timezone: Europe/Paris)
chdir("/maquette");
$date   = date('Y-m-d H:i');
$minute = date('i');
require 'config.php';
//$minute = '15';
// Test de connection a la base de donnes 
try {
    $bdd = new PDO('mysql:host=localhost;dbname=maquette;charset=utf8', DB_USER, DB_PASSWORD);
}
catch (Exception $e) {
    die('Erreur : ' . $e->getMessage());
}
//Telechargement et Chargement du fichier channels
file_put_contents("channels.xml", fopen('http://193.54.197.212/channels.xml', 'r'));
$Capteurs = simplexml_load_file("channels.xml");
///////////////////////////////////////////// Enregistrement des valeurs  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Insertion des Capteurs
// REMOTE CHANNELS
foreach ($Capteurs->RemoteChannels->Channel as $channel) {
    print "Nom du capteur: {$channel->Tag} <br />\n";
    print "Type de valeur {$channel->Unit}<br />\n";
    print "$date <br />\n";
    //Si 15 minutes
    if ($minute == '15') {
        if ($channel->Unit == 'C' || $channel->Unit == '°C') {
            if ($channel->Tag == 'M4IST') {
                $valeur = $channel->Value * 0.01;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            } else {
                print "Temperature <br /> \n";
                $valeur = $channel->Value * 0.10;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            }
        }
        if ($channel->Unit == '%' || $channel->Unit == '%H') {
            if ($channel->Tag == 'M4ISH') {
                $valeur = $channel->Value * 0.01;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            } else {
                print "Humidite <br /> \n";
                $valeur = $channel->Value * 0.10;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            }
        }
        if ($channel->Unit == 'PPM' || $channel->Unit == 'ppm') {
            $valeur = $channel->Value * 0.10;
            print "CO2 <br /> \n";
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15='$valeur' WHERE TagCapteur ='$channel->Tag'");
            print "Valeur: {$valeur} <br />\n";
        }
    }
    //Si 30 minutes
    if ($minute == '30') {
        if ($channel->Unit == 'C' || $channel->Unit == '°C') {
            if ($channel->Tag == 'M4IST') {
                $valeur = $channel->Value * 0.01;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            } else {
                print "Temperature <br /> \n";
                $valeur = $channel->Value * 0.10;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            }
        }
        if ($channel->Unit == '%' || $channel->Unit == '%H') {
            if ($channel->Tag == 'M4ISH') {
                $valeur = $channel->Value * 0.01;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            } else {
                print "Humidite <br /> \n";
                $valeur = $channel->Value * 0.10;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            }
        }
        if ($channel->Unit == 'PPM' || $channel->Unit == 'ppm') {
            $valeur = $channel->Value * 0.10;
            print "CO2 <br /> \n";
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30='$valeur' WHERE TagCapteur ='$channel->Tag'");
            print "Valeur: {$valeur} <br />\n";
        }
    }
    //Si 45 minutes
    if ($minute == '45') {
        if ($channel->Tag == 'M4IST') {
            $valeur = $channel->Value * 0.01;
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45='$valeur' WHERE TagCapteur ='$channel->Tag'");
            print "Valeur: {$valeur} <br />\n";
        } else {
            print "Temperature <br /> \n";
            $valeur = $channel->Value * 0.10;
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45='$valeur' WHERE TagCapteur ='$channel->Tag'");
            print "Valeur: {$valeur} <br />\n";
        }
        if ($channel->Unit == '%' || $channel->Unit == '%H') {
            if ($channel->Tag == 'M4ISH') {
                $valeur = $channel->Value * 0.01;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            } else {
                print "Humidite <br /> \n";
                $valeur = $channel->Value * 0.10;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
            }
        }
        if ($channel->Unit == 'PPM' || $channel->Unit == 'ppm') {
            $valeur = $channel->Value * 0.10;
            print "CO2 <br /> \n";
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45='$valeur' WHERE TagCapteur ='$channel->Tag'");
            print "Valeur: {$valeur} <br />\n";
        }
    }
    //Si 1h
    if ($minute == '0') {
        $connect = mysql_connect("localhost", "root", "IrisVitry51");
        mysql_select_db("maquette");
        if ($channel->Unit == 'C' || $channel->Unit == '°C' || $channel->Unit == '?C') {
            if ($channel->Tag == 'M4IST') {
                $valeur = $channel->Value * 0.01;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
                print "Temperature <br /> \n";
                $req15 = "SELECT Mesure15 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur15 = mysql_query($req15, $connect) or die(mysql_error());
                $req30 = "SELECT Mesure30 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur30 = mysql_query($req30, $connect) or die(mysql_error());
                $req45 = "SELECT Mesure45 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur45 = mysql_query($req45, $connect) or die(mysql_error());
                $req60 = "SELECT Mesure60 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur60 = mysql_query($req60, $connect) or die(mysql_error());
                $resultat15 = mysql_result($valeur15, 0);
                $resultat30 = mysql_result($valeur30, 0);
                $resultat45 = mysql_result($valeur45, 0);
                $resultat60 = mysql_result($valeur60, 0);
                print "Valeur {$resultat15}";
                print "Valeur {$resultat30}";
                print "Valeur {$resultat45}";
                print "Valeur {$resultat60}";
                $valeur1 = ($resultat15 + $resultat30 + $resultat45 + $resultat60) / 4;
                print "Valeur1 {$valeur1}";
                $bdd->exec("INSERT INTO MesureCapteur(Valeur,Date,TagCapteur,Unite) VALUES('$valeur','$date','$channel->Tag','C')");
            } else {
                print "Temperature <br /> \n";
                $valeur = $channel->Value * 0.10;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
                $req15 = "SELECT Mesure15 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur15 = mysql_query($req15, $connect) or die(mysql_error());
                $req30 = "SELECT Mesure30 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur30 = mysql_query($req30, $connect) or die(mysql_error());
                $req45 = "SELECT Mesure45 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur45 = mysql_query($req45, $connect) or die(mysql_error());
                $req60 = "SELECT Mesure60 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur60 = mysql_query($req60, $connect) or die(mysql_error());
                $resultat15 = mysql_result($valeur15, 0);
                $resultat30 = mysql_result($valeur30, 0);
                $resultat45 = mysql_result($valeur45, 0);
                $resultat60 = mysql_result($valeur60, 0);
                print "Valeur {$resultat15}";
                print "Valeur {$resultat30}";
                print "Valeur {$resultat45}";
                print "Valeur {$resultat60}";
                $valeur1 = ($resultat15 + $resultat30 + $resultat45 + $resultat60) / 4;
                print "Valeur1 {$valeur1}";
                $bdd->exec("INSERT INTO MesureCapteur(Valeur,Date,TagCapteur,Unite) VALUES('$valeur','$date','$channel->Tag','C')");
            }
        }
        if ($channel->Unit == '%' || $channel->Unit == '%H') {
            if ($channel->Tag == 'M4ISH') {
                $valeur = $channel->Value * 0.01;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
                print "Temperature <br /> \n";
                $req15 = "SELECT Mesure15 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur15 = mysql_query($req15, $connect) or die(mysql_error());
                $req30 = "SELECT Mesure30 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur30 = mysql_query($req30, $connect) or die(mysql_error());
                $req45 = "SELECT Mesure45 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur45 = mysql_query($req45, $connect) or die(mysql_error());
                $req60 = "SELECT Mesure60 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur60 = mysql_query($req60, $connect) or die(mysql_error());
                $resultat15 = mysql_result($valeur15, 0);
                $resultat30 = mysql_result($valeur30, 0);
                $resultat45 = mysql_result($valeur45, 0);
                $resultat60 = mysql_result($valeur60, 0);
                print "Valeur {$resultat15}";
                print "Valeur {$resultat30}";
                print "Valeur {$resultat45}";
                print "Valeur {$resultat60}";
                $valeur1 = ($resultat15 + $resultat30 + $resultat45 + $resultat60) / 4;
                print "Valeur1 {$valeur1}";
                $bdd->exec("INSERT INTO MesureCapteur(Valeur,Date,TagCapteur,Unite) VALUES('$valeur','$date','$channel->Tag','%')");
            } else {
                print "Humidite <br /> \n";
                $valeur = $channel->Value * 0.10;
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60='$valeur' WHERE TagCapteur ='$channel->Tag'");
                print "Valeur: {$valeur} <br />\n";
                $req15 = "SELECT Mesure15 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur15 = mysql_query($req15, $connect) or die(mysql_error());
                $req30 = "SELECT Mesure30 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur30 = mysql_query($req30, $connect) or die(mysql_error());
                $req45 = "SELECT Mesure45 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur45 = mysql_query($req45, $connect) or die(mysql_error());
                $req60 = "SELECT Mesure60 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur60 = mysql_query($req60, $connect) or die(mysql_error());
                $resultat15 = mysql_result($valeur15, 0);
                $resultat30 = mysql_result($valeur30, 0);
                $resultat45 = mysql_result($valeur45, 0);
                $resultat60 = mysql_result($valeur60, 0);
                print "Valeur {$resultat15}";
                print "Valeur {$resultat30}";
                print "Valeur {$resultat45}";
                print "Valeur {$resultat60}";
                $valeur1 = ($resultat15 + $resultat30 + $resultat45 + $resultat60) / 4;
                print "Valeur1 {$valeur1}";
                $bdd->exec("INSERT INTO MesureCapteur(Valeur,Date,TagCapteur,Unite) VALUES('$valeur','$date','$channel->Tag','%')");
            }
        }
        if ($channel->Unit == 'PPM' || $channel->Unit == 'ppm') {
            $valeur = $channel->Value * 0.10;
            print "CO2 <br /> \n";
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60='$valeur' WHERE TagCapteur ='$channel->Tag'");
            print "Valeur: {$valeur} <br />\n";
            $req15 = "SELECT Mesure15 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
            $valeur15 = mysql_query($req15, $connect) or die(mysql_error());
            $req30 = "SELECT Mesure30 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
            $valeur30 = mysql_query($req30, $connect) or die(mysql_error());
            $req45 = "SELECT Mesure45 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
            $valeur45 = mysql_query($req45, $connect) or die(mysql_error());
            $req60 = "SELECT Mesure60 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
            $valeur60 = mysql_query($req60, $connect) or die(mysql_error());
            $resultat15 = mysql_result($valeur15, 0);
            $resultat30 = mysql_result($valeur30, 0);
            $resultat45 = mysql_result($valeur45, 0);
            $resultat60 = mysql_result($valeur60, 0);
            print "Valeur {$resultat15}";
            print "Valeur {$resultat30}";
            print "Valeur {$resultat45}";
            print "Valeur {$resultat60}";
            $valeur1 = ($resultat15 + $resultat30 + $resultat45 + $resultat60) / 4;
            print "Valeur1 {$valeur1}";
            $bdd->exec("INSERT INTO MesureCapteur(Valeur,Date,TagCapteur,Unite) VALUES('$valeur1','$date','$channel->Tag','ppm')");

        }
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15= '0' WHERE TagCapteur='$channel->Tag'");
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30= '0' WHERE TagCapteur='$channel->Tag'");
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45= '0' WHERE TagCapteur='$channel->Tag'");
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60= '0' WHERE TagCapteur='$channel->Tag'");
    }

}
unlink("channels.xml");
////////////////////////////////////////// NE PAS UTILISER ///////////////////////////////////
//$bdd->exec("INSERT INTO capteur(TagCapteur,idTypeCapteur,Zone,Salle,Emplacement) VALUES('$channel->Tag','1','1','Exercice 1','sortie')");
//mysql_query("INSERT INTO articles SET nom='".($article->nom)."' AND id='".($article->id)."'") or die("Erreur MySQL : ".mysql_error());
//var_dump($channel->Unit);
//$bdd ->exec('SET NAMES utf8');
?>
Here the second script : 

        <?php
    ///////////////////////////////////////////// Preparation \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    //Recuperation des valeurs obligatoires
    //Preparation de la DATE
    chdir("/maquette");
    require 'config.php';
    date_default_timezone_set('Europe/Paris'); // Mise a la bonne heure (Timezone: Europe/Paris)
    $date   = date('Y-m-d H:i');
    $minute = date('i');

    // Test de connection a la base de donnes 
    try {
        $bdd = new PDO('mysql:host=localhost;dbname=Microcreche;charset=utf8', DB_USER, DB_PASSWORD);
    }
    catch (Exception $e) {
        die('Erreur : ' . $e->getMessage());
    }
    //Telechargement et Chargement du fichier channels
    file_put_contents("channels.xml", fopen('http://80.13.148.4/channels.xml', 'r'));
    $Capteurs = simplexml_load_file("channels.xml");
    ///////////////////////////////////////////// Enregistrement des valeurs  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    //Insertion des Capteurs
    // REMOTE CHANNELS
    foreach ($Capteurs->RemoteChannels->Channel as $channel) {
        //Si 15 minutes

        if ($minute == '15') {
            if ($channel->Unit == 'C' || $channel->Unit == '°C') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
                print "ok";
            }
            if ($channel->Unit == '%' || $channel->Unit == '%H') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
            }
            if ($channel->Unit == 'PPM' || $channel->Unit == 'ppm') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
            }

        }
        //Si 30 minutes
        if ($minute == '30') {
            if ($channel->Unit == 'C' || $channel->Unit == '°C' || $channel->Unit == 'ºC') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
            }
            if ($channel->Unit == '%' || $channel->Unit == '%H') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
            }
            if ($channel->Unit == 'PPM' || $channel->Unit == 'ppm') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
            }

        }
        //Si 45 minutes
        if ($minute == '45') {
            if ($channel->Unit == 'C' || $channel->Unit == '°C' || $channel->Unit == 'ºC') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
            }
            if ($channel->Unit == '%' || $channel->Unit == '%H') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
            }
            if ($channel->Unit == 'PPM' || $channel->Unit == 'ppm') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
            }
        }
        //Si 1h
        if ($minute == '0') {
            $connect = mysql_connect("localhost", "root", "IrisVitry51")or die(mysql_error());
            mysql_select_db('Microcreche',$connect);
            if ($channel->Unit == 'C' || $channel->Unit == '°C' || $channel->Unit == 'ºC') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
                $req15 = "SELECT Mesure15 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur15 = mysql_query($req15, $connect) or die(mysql_error());
                $req30 = "SELECT Mesure30 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur30 = mysql_query($req30, $connect) or die(mysql_error());
                $req45 = "SELECT Mesure45 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur45 = mysql_query($req45, $connect) or die(mysql_error());
                $req60 = "SELECT Mesure60 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur60 = mysql_query($req60, $connect) or die(mysql_error());
                $resultat15 = mysql_result($valeur15, 0);
                $resultat30 = mysql_result($valeur30, 0);
                $resultat45 = mysql_result($valeur45, 0);
                $resultat60 = mysql_result($valeur60, 0);
                $valeur1    = ($resultat15 + $resultat30 + $resultat45 + $resultat60) / 4;
                $bdd->exec("INSERT INTO MesureCapteur(Valeur,Date,TagCapteur,Unite) VALUES('$valeur1','$date','$channel->Tag','C')");
            }
            if ($channel->Unit == '%' || $channel->Unit == '%H') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
                $req15 = "SELECT Mesure15 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur15 = mysql_query($req15, $connect) or die(mysql_error());
                $req30 = "SELECT Mesure30 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur30 = mysql_query($req30, $connect) or die(mysql_error());
                $req45 = "SELECT Mesure45 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur45 = mysql_query($req45, $connect) or die(mysql_error());
                $req60 = "SELECT Mesure60 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur60 = mysql_query($req60, $connect) or die(mysql_error());
                $resultat15 = mysql_result($valeur15, 0);
                $resultat30 = mysql_result($valeur30, 0);
                $resultat45 = mysql_result($valeur45, 0);
                $resultat60 = mysql_result($valeur60, 0);
                $valeur1    = ($resultat15 + $resultat30 + $resultat45 + $resultat60) / 4;
                $bdd->exec("INSERT INTO MesureCapteur(Valeur,Date,TagCapteur,Unite) VALUES('$valeur1','$date','$channel->Tag','%')");
            }
            if ($channel->Unit == 'PPM' || $channel->Unit == 'ppm') {
                $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60='$channel->Value' WHERE TagCapteur ='$channel->Tag'");
                $req15 = "SELECT Mesure15 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur15 = mysql_query($req15, $connect) or die(mysql_error());
                $req30 = "SELECT Mesure30 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur30 = mysql_query($req30, $connect) or die(mysql_error());
                $req45 = "SELECT Mesure45 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur45 = mysql_query($req45, $connect) or die(mysql_error());
                $req60 = "SELECT Mesure60 FROM MesureCapteurTemp WHERE TagCapteur='$channel->Tag'";
                $valeur60 = mysql_query($req60, $connect) or die(mysql_error());
                $resultat15 = mysql_result($valeur15, 0);
                $resultat30 = mysql_result($valeur30, 0);
                $resultat45 = mysql_result($valeur45, 0);
                $resultat60 = mysql_result($valeur60, 0);
                $valeur1    = ($resultat15 + $resultat30 + $resultat45 + $resultat60) / 4;
                $bdd->exec("INSERT INTO MesureCapteur(Valeur,Date,TagCapteur,Unite) VALUES('$valeur1','$date','$channel->Tag','ppm')");
            }
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure15= '0' WHERE TagCapteur='$channel->Tag'");
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure30= '0' WHERE TagCapteur='$channel->Tag'");
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure45= '0' WHERE TagCapteur='$channel->Tag'");
            $bdd->exec("UPDATE MesureCapteurTemp SET Mesure60= '0' WHERE TagCapteur='$channel->Tag'");
        } 
    }
    unlink("channels.xml");
    ?>

How can I fix it?

  • Before running a script in cron, you should first test and verify that it works from the commandline. This is the easiest way to see how it will behave. The most likely culprit is probably the location of your dependency files such as your config.php, as well as your environment variables. Run it from the commandline, then work with whatever output, or errors you get. – L. D. James May 29 '17 at 23:06
  • If you want to say that i try with a command like php to execute my script the script works. The dependency is in the same folder than my script. But something curious happen : the same script on a another folder works now IDK why. – gilles33366 May 29 '17 at 23:25
1

Your problem is, as I mention, your environment. Looking at your php script and the crontab entry calling it, there isn't any reference to your changing to the directory containing dependency files. Your default current working directory is your home folder (~/). Your script folder isn't the same as the directory your cron is running.

Also your myscript.php file is using the require 'config.php'; directive, but it's not pointing to the /myscript/ folder where it's located.

One of the easiest ways to remedy this is to change your current working directory to the directory containing your script files.

Edit your file

Change from:

<?php
///////////////////////////////////////////// Preparation \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Recuperation des valeurs obligatoires
//Preparation de la DATE
date_default_timezone_set('Europe/Paris'); // Mise a la bonne heure (Timezone: Europe/Paris)
$date   = date('Y-m-d H:i');
$minute = date('i');
require 'config.php';

Change to:

<?php
///////////////////////////////////////////// Preparation \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Recuperation des valeurs obligatoires
//Preparation de la DATE
chdir("/myscript");
date_default_timezone_set('Europe/Paris'); // Mise a la bonne heure (Timezone: Europe/Paris)
$date   = date('Y-m-d H:i');
$minute = date('i');
require 'config.php';

You mentioned debug. I don't know the debug method you are using, but you may find a convenient way of debugging your cron scripts is to redirect it to a log file. By default, the output goes to your /var/log/syslog. Redirecting the output to a preferred file will give you a cleaner log.

Add the shebang header and make your initial script executable from the commandline. This will provide the functionality for a convenient log file redirection.

Considerations for your crontab entry and script file

Crontab entry:

Cron : */15 * * * * /myscript/myscript.php >> /myscript/script.log 2>> myscript.err

PHP Script:

#!/usr/bin/php
<?php
///////////////////////////////////////////// Preparation \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Recuperation des valeurs obligatoires
//Preparation de la DATE
chdir("/myscript");
date_default_timezone_set('Europe/Paris'); // Mise a la bonne heure (Timezone: Europe/Paris)
$date   = date('Y-m-d H:i');
$minute = date('i');
require 'config.php';

Don't forget to chmod +x your /myscript/myscript.php.

Final Resolution

The issue was resolved in a chat discussion (see the comments). The main problem(s) (and most likely the ultimate problem) was the location of files. Running the application from the commandline and addressing the errors resolved the issues.

The problem with two php scripts in cron was resolved by studying the log (the standard output) was showing just one instance of the two scripts running. That was due to confusion of the >> versus the > output redirection. The single greater than symbol was overwriting the previous instance. The >> redirect resolved that part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.