public function prepareRest() { /** @var FilterPastResults $model */ $model = Yii::createObject(['class' => FilterPastResults::className(), 'scenario' => 'filter']); $result = ['content' => [], 'total' => [], 'errors' => []]; include_once Yii::$app->getBasePath() . DIRECTORY_SEPARATOR . 'crons' . DIRECTORY_SEPARATOR . 'api.php'; if ($model->load(Yii::$app->request->post()) && $model->validate()) { $data = ['loc' => $model->loc, 'action' => $model->action, 'DF' => strtotime(date($model->dateFrom . ' 00:00:00')) * 1000, 'DT' => strtotime(date($model->dateTo . ' 23:59:59')) * 1000, 'Sport' => $model->sports, 'collapsedSports' => false, 'substr' => $model->search, 'categoriesPerPage' => $model->categoriesPerPage, 'page' => $model->page]; $url = 'http://212.38.167.37/resultsproxy/getresultsxml3.aspx'; $xml = apiReadUrlXml($url, $data); $array = apiParseXml($xml); if ($array['status'] === true) { $array = obj2array($array['result']); $result['total'] = $array['@attributes']; if ($array['@attributes']['page'] > $array['@attributes']['totalpages']) { $result['status'] = 3; return $result; } if ($array['@attributes']['count'] == 0) { $result['status'] = 2; $result['errors'][] = Yii::t('bet', 'No results were found that met all the given criteria'); } else { include_once $this->getViewPath() . DIRECTORY_SEPARATOR . 'template.php'; $array = $array['sports']['PSport']; if (sizeof($array) == 2 && isset($array['@attributes']) && isset($array['Groups'])) { $array = [$array]; } if ($model->page == 1) { $result['content'][] = '<table role="presentation" cellpadding="0" cellspacing="0">'; $result['content'][] = '<tbody>'; } foreach ($array as $sport) { if (is_array($sport['@attributes'])) { sportBlock($result['content'], $sport['@attributes']['id'], $sport['@attributes']['code'], $sport['@attributes']['name'], $sport); } } if ($model->page == 1) { $result['content'][] = '</tbody>'; $result['content'][] = '</table>'; } //$result['content'] = $array; } } else { $result['errors'] = $array['errors']; } } else { $result['status'] = false; $result['errors'] = array_values($model->getErrors()); } //?loc=ru-RU&action=GETRESULTS&DF=1436043600000&DT=1436129999999&Sport=1763111,1763108,1763113,1763081,1763099,1762805, //1763102,1763049,1763104,1763048,1763105,1763114,1763082,1763068,1763057,1762821,1763040,1763059,1763077,1763085,1763116, //1763096,1763070,1763061,1781423,1763112,1763117,1763115,1763109,1763110,1763052,1781422,1763054,1763090,1762785,1763037, //1763091,1763072,1781414,1763045,1763044,1763056,1762822,1763106,1763080,1763079,1763060,2576760,1763051,1763053,1763075, //1763076,1763062,1763083,1763046,1762818,1762803,1763101,1763118,1762823,1763064,1763100,1763107,1762801,1763043,1763066, //1763094,1763067,1763073,1763078,1762798,1762824,1763074,1763038,1763058,1763036,1763097,1763063,1763050,1763069,1762800, //1763042,1781407,1763086,1763088,1763103,1763093&collapsedSports=false&page=1 return $result; }
// * * * * * /usr/bin/php -f /home/totorat/sar/crons/get_live_results.php >> /home/totorat/sar/runtime/logs/get_live_results.log 2>&1 include_once __DIR__ . DIRECTORY_SEPARATOR . 'api.php'; set_time_limit(100); for ($x = 1; $x <= 12; $x++) { sleep(5); $url = 'http://212.38.167.37/reslive/getreslive2.aspx'; echo "\r\n------------------------------------------------------------------------------------------\r\n" . "\r\n" . "\r\n" . 'Read url: ' . $url . "\r\n"; $xml = apiReadUrlXml($url, ['local' => 'en-GB']); if (!is_string($xml) && $xml === false) { die('Error receiving xml from url:' . $url); } echo 'Success. String length: ' . strlen($xml) . "\r\n"; echo substr($xml, 0, 200) . "\r\n"; echo 'Parsing xml...' . "\r\n"; $xml = apiParseXml($xml); if ($xml['status'] === false) { die('Error parsing xml from url:' . $url . ' with errors:' . var_export($xml['errors'], true)); } echo 'Parsing Success.' . "\r\n"; $file_path = PATH_RUNTIME_LIVE . DIRECTORY_SEPARATOR . 'array_live_' . time() . '.php'; $xml = var_export(obj2array($xml['result']), true); echo substr($xml, 0, 200) . "\r\n"; echo 'Writing to file.' . $file_path . "\r\n"; file_put_contents($file_path, '<? return ' . $xml . ';'); if (file_exists($file_path)) { echo 'Success. File size: ' . filesize($file_path) . "\r\n"; } else { echo 'Error writing file. ' . "\r\n"; } }