input->is_cli_request()){ error_reporting(E_ALL); $this->load->model('Services_model'); //$totalpage = 10213; // get total page $totalpage = 1; $default = $this->Services_model->getCollaborator(2,1,100); //var_dump($default); $data = mb_convert_encoding($default, 'UTF-8', 'ISO-8859-1'); if($data){ $xml = simplexml_load_string($data); $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/"); $xml = $xml->xpath('//S:Body'); $xml = $xml[0]; $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/"); $totalpage = $xml->xpath('//return//totalpage'); $totalpage = (int)$totalpage[0]; } for ($i=1; $i<=$totalpage; $i++){ $result = $this->Services_model->getCollaborator(2,$i,100); $data = mb_convert_encoding($result, 'UTF-8', 'ISO-8859-1'); if($data && $data != -1){ $xml = simplexml_load_string($data); $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/"); $xml = $xml->xpath('//S:Body'); $xml = $xml[0]; $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/"); $lst = $xml->xpath('//return//lst'); foreach($lst as $item){ $item = (array)$item; $data = array( 'address'=> (string)$item['address'], 'code'=>(string)$item['code'], 'district'=>(string)$item['district'], 'email'=>(string)$item['email'], 'id'=>(int)$item['id'], 'full_name'=>(string)$item['name'], 'cellphone'=>(string)$item['phone'], 'precinct'=>(string)$item['precinct'], 'province'=>(string)$item['province'], 'created_time'=>date('Y-m-d H:i:s'), 'updated_time'=>date('Y-m-d H:i:s') ); write_file('./log/sync_collaborator.log', var_export($data, TRUE), FOPEN_WRITE_CREATE); if ((string)$item['phone']){ $this->Services_model->syncCollaborator($data); } } }else{ $logMsg = date('Y-m-d H:i:s') . " Result is null \n"; write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE); } } } } }