public function actionGetURL($start = null, $num = null) { //获取URL地址 if (!empty($start) && !empty($num)) { $ids = $this->getUserIds($start, $num); foreach ($ids as $id) { $url = $this->getURL($id); echo $id . ' : '; //.$url; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1"); curl_setopt($ch, CURLOPT_NOBODY, false); // remove body curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $head = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); switch ($httpCode) { case 200: echo ' 200 ok'; $model = TianjiUserJson::model()->findByPk($id); if ($model === null) { $model = new TianjiUserJson(); $model->userid = $id; $model->json = $head; $model->save(); } break; case 500: echo ' 500'; break; default: echo ' ' . $httpCode; break; } echo "\n"; } } else { echo "Hello World!!!"; } }
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1"); curl_setopt($ch, CURLOPT_NOBODY, false); // remove body curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $head = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); switch ($httpCode) { case 200: echo ' 200 ok'; $model = TianjiUserJson::model()->findByPk($id); if ($model === null) { $model = new TianjiUserJson(); $model->userid = $id; $model->json = $head; $model->save(); } break; case 500: echo ' 500'; break; default: echo ' ' . $httpCode; break; } echo "<br/>"; } } else {
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = TianjiUserJson::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }