O script PHP está falhando com o cron

0

Eu quero usar o cron com 2 scripts php.

Quando eu executo estes scripts manualmente com php /soncourt/index.php (por exemplo) no meu servidor de destino, ele funciona, mas quando eu quero usar o CRON ele falha

Primeiro cron:

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

Segundo cron:

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

Este é o primeiro 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");
    ?>

Como posso corrigir isso?

    
por gilles33366 30.05.2017 / 00:08

1 resposta

2

O seu problema é, como eu menciono, o seu ambiente. Olhando para o seu script php e a entrada crontab chamando, não há qualquer referência à sua mudança para o diretório que contém arquivos de dependência. Seu current working directory padrão é sua pasta pessoal ( ~/ ). Sua pasta de script não é o mesmo que o diretório que seu cron está executando.

Além disso, o arquivo myscript.php está usando a diretiva require 'config.php'; , mas não está apontando para a pasta /myscript/ onde está localizada.

Uma das maneiras mais fáceis de corrigir isso é alterar o diretório de trabalho atual para o diretório que contém seus arquivos de script.

Edite seu arquivo

Alterar de:

<?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';

Alterar para:

<?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';

Você mencionou o debug. Eu não sei o método de depuração que você está usando, mas você pode encontrar uma maneira conveniente de depurar seus scripts cron para redirecioná-lo para um arquivo de log. Por padrão, a saída vai para o seu /var/log/syslog . Redirecionar a saída para um arquivo preferido fornecerá um log mais limpo.

Adicione o cabeçalho shebang e torne seu script inicial executável a partir da linha de comando. Isso fornecerá a funcionalidade para um redirecionamento conveniente do arquivo de log.

Considerações sobre sua entrada e arquivo de script do crontab

Entrada do Crontab:

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

Script PHP:

#!/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';

Não se esqueça de chmod +x your /myscript/myscript.php .

Resolução final

O problema foi resolvido em uma discussão por chat (veja os comentários). O problema principal (e provavelmente o problema final) era a localização dos arquivos. Executar o aplicativo a partir da linha de comando e resolver os erros resolveu os problemas.

O problema com dois scripts php no cron foi resolvido estudando o log (a saída padrão) mostrando apenas uma instância dos dois scripts em execução. Isso ocorreu devido à confusão do redirecionamento >> versus > output. O único símbolo maior que estava sobrescrevendo a instância anterior. O >> redirect resolveu essa parte.

    
por L. D. James 30.05.2017 / 02:16