1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
function service($reports)
{
global $database, $array;
error_log("debut execution service");
$url = $array['URL_ROOT'].'/func/xxxx.php';
$file = 's_sendData.json';
$current = file_get_contents($file);
$current .= 'url getreport: ' . $url . "\n \n";
$reports_count = count($reports);
$current .= 'reports_count : ' . $reports_count . "\n \n";
for ($i = 0; $i < $reports_count; $i++) {
$postdata = http_build_query(
array(
'cmd' => 'report',
'schedule' => true
);
$current .= 'post data : ' . json_encode($postdata) . "\n \n";
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata,
),
'ssl' => array('verify_peer' => false),
);
$current .= 'opts : ' . json_encode($opts) . "\n";
$context = stream_context_create($opts);
try {
if (file_exists($url)) {
$content = file_get_contents($url, false, $context);
$current .= 'content : ' . $content . "\n\n";
}else{
$content = 'pas de fichier' ;
$current .= 'content : ' . $content . "\n\n";
}
} catch (Exception $e) {
$current .= 'Exception reçue : ' . $e->getMessage() . "\n \n";
}
// Écrit le résultat dans le fichier
file_put_contents($file, $current, FILE_APPEND);
}
error_log("fin execution service");
}
} |
Partager