* @since 2.0 */ class SyncController extends Controller { /** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. * @return int Exit code */ public function actionIndex() { if ($this->is_connected()) { $sync = \app\models\SyncUrl::find()->one(); if ($sync) { $logs = \app\models\WaitingReq::find()->all(); foreach ($logs as $key => $value) { // $start = round(microtime(true) * 1000); $contentJSON = json_decode($value->content); $imgPath = $contentJSON->image; $imgBase64 = base64_encode(file_get_contents($imgPath)); $contentJSON->image = $imgBase64; $newValue = json_encode($contentJSON); $options = [ 'http' => [ 'header' => "Content-Type: application/json", 'method' => "POST", 'content' => $newValue ] ]; $res = json_decode(file_get_contents($sync->data, false, stream_context_create($options)), true); if ($res['status'] == 1000) { $modelRes = new \app\models\ResponseReq(); $modelRes->create(json_encode($res)); $value->delete(); // Delete image unlink($imgPath); } // $end = round(microtime(true) * 1000); // $timeDuration = $end - $start; // Yii::info("Time:" . $timeDuration . " - " . $res, "cloud-response"); // var_dump($res); // var_dump($timeDuration); } } } return ExitCode::OK; } function is_connected() { $connected = @fsockopen("google.com", 80); //website, port (try 80 or 443) if ($connected) { $is_conn = true; //action when connected fclose($connected); } else { $is_conn = false; //action in connection failure } return $is_conn; } }