The php guzzle OpenCPU POST request for the simple R DemoPackage function
$response = $client->request('POST','http://178.254.13.220/ocpu/library/DemoPackage/R/addition/json', ['json' => $jsontext, 'debug' => true]);
stucks during execution on a ubuntu server. The simple addition function adds 2 numbers and returns the sum as result (see code below).
If "POST" is changed to "GET", the request delivers the correct source code of the function addition in the variable body by the command : $body = $response->getBody();
On the local Mac computer, where the function was developed and tested, the DemoPackage works fine. My other R packages on the ubuntu server run perfect, however I could not find the error in this simple example of adding 2 numbers.
addition <- function(jsontext)
{
tmp <- unlist(jsonlite::fromJSON(jsontext))
a <- as.numeric(tmp[[1]])
b <- as.numeric(tmp[[2]])
c <- a + b
aValue <- as.character(round(a))
bValue <- as.character(round(b))
cValue <- as.character(round(c))
pValue_dataframe <- data.frame(aValue,bValue,cValue)
result <- list(sum = pValue_dataframe)
result_json <- toJSON(result)
return(result_json)
}
The php code sucks while executing the POST request. With the http request debug option there is an error message, however I am not able to interpret it and or know what to do. The error message is:
Found bundle for host 178.254.13.220: 0x28d6b90 * Re-using existing connection! (#0) with host 178.254.13.220 * Connected to 178.254.13.220 (178.254.13.220) port 80 (#0) > POST /ocpu/library/DemoPackage/R/addition/json HTTP/1.1 User-Agent: GuzzleHttp/6.2.1 curl/7.35.0 PHP/5.5.9-1ubuntu4.20 Content-Type: application/json Host: 178.254.13.220 Content-Length: 67 * upload completely sent off: 67 out of 67 bytes < HTTP/1.1 400 Bad Request * Server nginx is not blacklisted < Server: nginx < Date: Thu, 04 Apr 2019 13:29:58 GMT < Content-Type: text/plain; charset=utf-8 < Transfer-Encoding: chunked < Connection: keep-alive < Access-Control-Allow-Origin: * < Access-Control-Expose-Headers: Location, X-ocpu-session, Content-Type, Cache-Control < Access-Control-Allow-Headers: Origin, Content-Type, Accept, Accept-Encoding, Cache-Control, Authorization < Access-Control-Allow-Credentials: true < X-ocpu-r: R version 3.1.3 (2015-03-09) < X-ocpu-locale: en_US.UTF-8 < X-ocpu-time: 2019-04-04 15:29:58 CEST < X-ocpu-version: 1.4.7 < X-ocpu-server: rApache < Vary: Accept-Encoding < X-Powered-By: PleskLin < * Connection #0 to host 178.254.13.220 left intact