Last active
August 29, 2015 13:57
-
-
Save Ser1ous/9757837 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$start = microtime(true); | |
$n = $_GET['keyssssss'];//Получаем текущий номер файла | |
if($n == "") | |
{ | |
unset($_SESSION['position']); | |
unset($_SESSION['arr']); | |
} | |
$n = (int)$_GET['fnumber']; | |
$handles = fopen('assets/csv/comand'.$n.'.sh', 'a+'); | |
$handle=fopen("assets/csv/part1.csv","r"); | |
$shablon = stream_get_line($handle,8096,"\r\n");//Получаем первую строку для того чтобы создать шаблон | |
$shablon = iconv('cp1251', 'utf-8', $shablon);//На всякий случай конвертируем в utf-8 | |
$shablon = explode(";", $shablon); | |
if(isset($_GET['position']))//Проверяем есть ли позиция, если есть, то сдвигаем на нужную позицию | |
{ | |
fseek($handle, $_GET['position']); | |
} | |
$handles_alt= fopen('assets/csv/comand.sh', 'a+'); | |
fwrite($handles_alt, "#!/bin/bash \r\n"); | |
fwrite($handles_alt, "sh /assets/csv/comand".$n.".sh& \r\n"); | |
fwrite($handles, "#!/bin/bash \r\n"); | |
fwrite($handles, 'D=$(date +%Y-%m-%d) | |
T=$(date +%H:%M:%S) | |
echo "$D"_"$T"_comand'.$n.'_start >> /assets/csv/output.date'." \r\n"); | |
while (!feof($handle)) { //Читаем до тех пор пока не конец файла | |
$line = stream_get_line($handle,8096,"\r\n"); | |
$line = iconv('cp1251', 'utf-8', $line); | |
$line_temp = explode(";", $line); | |
$line_merge = array_combine($shablon, $line_temp); | |
$line_merge = array_filter ($line_merge); | |
$line_merge['Артикул'] = (int)$line_merge['Артикул'];//Нужые мне столбцы конвертирую в INT | |
$line_merge['Категория'] = (int)$line_merge['Категория']; | |
$line_merge['Цена'] = (int)$line_merge['Цена']; | |
$json = json_encode($line_merge, JSON_UNESCAPED_UNICODE);//Кодирую в запрос для ElasticSearch | |
echo $json; | |
$send_string = "curl -XPOST localhost:9200/modx_shop/towar_base/".$line_temp[0]." -d '".$json."'";//Полный запрос, $line_temp[0] - хранит id товара | |
fwrite($handles, $send_string."\r\n"); | |
$time = microtime(true) - $start; | |
if($time>27)//Проверяю прошло ли 27 секунд, если прошло, то делаю обновление с нужной позицией. | |
{ | |
fwrite($handles, 'D=$(date +%Y-%m-%d) | |
T=$(date +%H:%M:%S) | |
echo "$D"_"$T"_comand'.$n.'_stop >> /assets/csv/output.date'); | |
$position = ftell($handle); | |
fclose($handle); | |
exec ("chmod +x assets/csv/comand".$n.".sh"); | |
$n++; | |
fclose($handles); | |
echo '<HEAD> | |
<META HTTP-EQUIV="REFRESH" CONTENT="1; URL=index.php?id=2&file='.$_GET['file'].'&position='.$position.'&fnumber='.$n.'"> | |
</HEAD>'; | |
exit(); | |
} | |
} | |
//На всякий случай отладочные данные о дате завершения записи | |
fwrite($handles, 'D=$(date +%Y-%m-%d) | |
T=$(date +%H:%M:%S) | |
echo "$D"_"$T"_comand'.$n.'_stop; >> /assets/csv/output.date'); | |
fclose($handle); | |
fclose($handles); | |
/*for($i=0; $i<=$n;$i++) | |
{ | |
fwrite($handles_alt, "wait; \r\n"); | |
}*/ | |
fwrite($handles_alt, 'D=$(date +%Y-%m-%d) | |
T=$(date +%H:%M:%S) | |
echo "$D"_"$T"_comand'.$n.'_stop_all >> /assets/csv/output.date | |
exit;'); | |
fclose($handles_alt); | |
exec ("chmod +x assets/csv/comand.sh"); | |
//echo date('l jS \of F Y h:i:s A'); | |
print_r($_SESSION['position']); | |
print_r($_SESSION['arr']); | |
$time = microtime(true) - $start; | |
printf('Скрипт выполнялся %.4F сек.', $time); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment