$guid, 'state' => $state, 'response' => $response ); var_dump(rest_send_json($url,$array,'UPDATE',false)); } /** * @param string $guid * @param string $filepath * @param array $args * @return mixed */ function replaceFileWithGuid($guid,$filepath, $args){ if(!isset($args['url'])) cli_report_error('missing return url'); $url = $args['url']; if(str_contains('app_dev.php',$url)) $urlTarget = "/app_dev.php/"; else $urlTarget = "/"; $urlTarget .= "public/api/worker/upload"; $urlTargetBasis = getTarget($args['url']).$urlTarget; $array = array( 'guid' => $guid, 'filepath' => $filepath, 'id' => $args['user'], ); return rest_send_json($urlTargetBasis,$array,'UPDATE'); } /** * @param $url * @param $array * @param string $method * @param bool $jsonDecode * @return mixed */ function rest_send_json($url, $array, $method = "POST", $jsonDecode = true){ $curl = curl_init($url); $data_string = json_encode($array); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string)) ); $curl_response = curl_exec($curl); if ($curl_response === false) { $info = curl_getinfo($curl); curl_close($curl); die('error occured during curl exec. Additioanl info: ' . print_r($info,true)); } curl_close($curl); if($method == 'UPDATE'){ //var_dump($curl_response); } if($jsonDecode){ $decoded = json_decode($curl_response,true); if (isset($decoded['error']) && $decoded['error'] === true) { cli_report_error($decoded['msg']); } } else { $decoded = $curl_response; } return $decoded; }