3v4l.org

run code in 300+ PHP versions simultaneously
<?php // token used for webservice authentication define('AUTH_TOKEN', 'UvNdcV8tYZUQCDc2W8re7CvHckWzQcT5'); // define the webservice endpoint path define('WS_ENDPOINT', 'https://tina.talmatravel.co.il/html/demoTina3/tina/disp.php?module=RemoteData/EntityManagementWs&action=handleRequest'); /** * Execute JSON webservice request * @param array $operationParams * @param stdClass $request * @throws Exception * @return mixed */ function restJsonCall(array $operationParams, stdClass $request = null) { $endPoint = str_replace(" ", "%20", WS_ENDPOINT).'&'.http_build_query($operationParams); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $endPoint); curl_setopt($ch, CURLOPT_POST, 1); if ($request) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request)); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec ($ch); if (curl_error($ch)) { throw new Exception('CURL eror: '.curl_errno($ch)); } $responseDecoded = json_decode($response); // invalid response if (!$responseDecoded) { throw new Exception('Invalid REST response: '.$response); } elseif ($responseDecoded->status!='ok') { throw new Exception('Error while executing operation: '. $responseDecoded->message); } return $responseDecoded; } // STEP 1: AUTHENTICATION // get the auth token first $operationParams_Authenticate = array('operation' => 'authenticate', 'authToken' => AUTH_TOKEN); $rq = new stdClass(); $rs = restJsonCall($operationParams_Authenticate, $rq); $token = $rs->sessionToken; // STEP 2: INSERT NEW SUPPLIER // initialize hit count; must be incremented on each request $hitCount = 0; // Prepare the request body $supplierInsertRequest = new stdClass(); $supplierInsertRequest->alias = 'COMPANY ALIAS'; $supplierInsertRequest->company = 'COMPANY NAME'; $supplierInsertRequest->email = 'companyname@noreply.com'; // assemble the operationParams array $operationParamsForSupplierInsert = array( 'sessionToken' => $token, 'hitCount' => ++$hitCount, 'entity' => 'supplier', 'operation' => 'insert', ); // call the operation $supplierInsertResponse = restJsonCall($operationParamsForSupplierInsert, $supplierInsertRequest); // display the response var_dump(json_encode($supplierInsertResponse, JSON_PRETTY_PRINT)); //get supplier id $idSupplier = $supplierInsertResponse->idEntity; // STEP 3: SELECT INSERTED SUPPLIER // for UPDATE / DELETE / SELECT, a valid ID must be specified // assemble the operationParams array: $operationParamsForSupplierSelect = array( 'sessionToken' => $token, 'hitCount' => ++$hitCount, 'entity' => 'supplier', 'operation' => 'select', 'id' => $idSupplier, ); // call the operation $supplierSelectResponse = restJsonCall($operationParamsForSupplierSelect); // display the response var_dump(json_encode($supplierSelectResponse, JSON_PRETTY_PRINT)); // STEP 4: DELETE INSERTED SUPPLIER // for UPDATE / DELETE / SELECT, a valid ID must be specified // assemble the operationParams array: $operationParamsForSupplierDelete = array( 'sessionToken' => $token, 'hitCount' => ++$hitCount, 'entity' => 'supplier', 'operation' => 'delete', 'id' => $idSupplier, ); // call the operation $supplierDeleteResponse = restJsonCall($operationParamsForSupplierDelete); // display the response var_dump(json_encode($supplierDeleteResponse, JSON_PRETTY_PRINT));
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/NsVk2:21 Stack trace: #0 /in/NsVk2(53): restJsonCall(Array, Object(stdClass)) #1 {main} thrown in /in/NsVk2 on line 21
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
46.99 ms | 401 KiB | 8 Q