Current Path : /home/bitrix/ext_www/vf.yacl.site/ |
Current File : /home/bitrix/ext_www/vf.yacl.site/test-for-report-send-file.php |
<? die('Устарел'); /* /opt/php71/bin/php -f /var/www/victorymuseum/data/www/historydepositarium.ru/report-send-file.php */ require(__DIR__.'/local/php_interface/constants.php'); foreach (scandir(__DIR__, SCANDIR_SORT_ASCENDING) as $f) { if (preg_match('~^report-(?<DATE>\d+-\d+-\d+).log~i', $f, $mt)) { if ((time() - strtotime($mt['DATE'])) > (60 * 60 * 24 * 7)) { unlink(__DIR__.'/'.$f); } } } $files = array(); foreach (scandir(__DIR__.'/upload/export/', SCANDIR_SORT_ASCENDING) as $f) { if (preg_match('~^report-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d\.xml$~i', $f)) $files[] = $f; } $t_start = time(); while (count($files) > 0 && (time() - $t_start) < 12) { $url = '/upload/export/'.array_shift($files); $xml = file_get_contents(__DIR__.$url); $file = curl_file_create(__DIR__.$url, 'application/xml', 'upload.xml'); $hash = strtoupper(hash('sha512', strtoupper(hash('sha512', $xml)).POST_KEY)); $postfields = array("DataSet" => $file); $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_POST => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => POST_URL.'/api/import/create', CURLOPT_POSTFIELDS => $postfields, CURLOPT_HTTPHEADER => ['X-Content-Signature-Key: '.POST_SIGNATURE_KEY, 'X-Content-Signature: '.$hash, 'Content-Type: multipart/form-data'], CURLOPT_CONNECTTIMEOUT => 12, CURLOPT_TIMEOUT => 12)); $t1 = microtime(true); $res = curl_exec($curl); $t2 = microtime(true); file_put_contents(__DIR__.'/report-'.date('Y-m-d').'.log', date('c') ."\t".$url ."\t".filesize(__DIR__.$url) ."\t".number_format($t2 - $t1, 6) ."\t".($res === false ? curl_error($curl) : 'OK') ."\r\n", FILE_APPEND); curl_close($curl); if ($res !== false) unlink(__DIR__.$url); sleep(1); } ?>