Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] REST API request does not reply until shell script is done

(This post was last modified: 07-11-2017, 10:58 PM by Datenshi.)

Hi All,

we are using REST API module by Chris Kacerguis. This is the code:

PHP Code:
public function getAllInformation_put()

           if (!empty($values['Network'])){
               $partial_response $partial_response.self::setNetworkParams($values['Network']);

           // Generate final REST response
           $response '{
                              "status": 200,
                              "message": "PUT '
           $response_array json_decode($responsetrue);
           $this->set_response($response_arrayREST_Controller::HTTP_OK); // CREATED (201) being the HTTP response code - Changed to 200
               shell_exec("/bin/reboot.sh &");

And the problem we find is that the response is not immediately sent and it waits for the reboot script to be executed (even we try to run it in the background and it has a sleep of 3 secs)

So sometimes we get network error by response, although the logic is well executed. Because probably the reboot timing and the set_response is too tight. 

Any idea about this issue or how we can try to fix it?

Thanks a lot in advance.

The client library that makes the request probably has an option for increasing the timeout.

I found the solution to this issue. Related to the way we execute the shell script. If I redirect both stdout and stderr to /dev/null, then background it, everything works fine.

Solution found here: LINK

Thanks @ivantcholakov for your suggestion.

Theme © iAndrew 2016 - Forum software by © MyBB