Error "session_start(): Ignoring session_start() because a session is already active"

Hello,

we got a weird issue on our DEV environnment ; the error message we got is "session_start(): Ignoring session_start() because a session is already active". Our dev is running under PHP 8.0.

This message is happening when a custom job tries to call, using External Resource Client, a external API.

The code was working when using CURL's call. We followed this article to transform our code : 

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.3/Integration/ExternalResourceClient/#Examples_of_Replacing_cURL

We do not open any session from our code ; we suppose this error is linked to the file_get_contents instruction (line 241) of 

src\Security\HttpClient\ExternalResourceClient.php

(but not for sure).

Any help, suggestion or whatever is welcome.

Fred

Parents
  • Here is our CALL method  

     

            // ExternalResourceClient GET
            try {
                $headers = [
                    'Authorization' => 'Basic ' . $token,
                    'Content-Type' => 'application/json'
                ];
                // Set timeout to 60 seconds and 10 max redirects
                $response = (new ExternalResourceClient(0, 10))->request('POST', $url, $body, $headers);
            } catch (RequestException $e) {
                $GLOBALS['log']->log('fatal', 'Error: ' . $e->getMessage());
                throw new \SugarApiExceptionError($e->getMessage());
            }
            $httpCode = $response->getStatusCode();
            if ($httpCode >= 400) {
                _ppl($response->getBody());
                throw new \SugarApiException("Request failed with status: " . $httpCode, null, null, $httpCode);
            }
            return $response->getBody()->getContents();

    the URL and token are defined in our config_override.php file.

    the body is a json_encode of a PHP array $body = json_encode($json);

    the error is catched when launching the request

Reply
  • Here is our CALL method  

     

            // ExternalResourceClient GET
            try {
                $headers = [
                    'Authorization' => 'Basic ' . $token,
                    'Content-Type' => 'application/json'
                ];
                // Set timeout to 60 seconds and 10 max redirects
                $response = (new ExternalResourceClient(0, 10))->request('POST', $url, $body, $headers);
            } catch (RequestException $e) {
                $GLOBALS['log']->log('fatal', 'Error: ' . $e->getMessage());
                throw new \SugarApiExceptionError($e->getMessage());
            }
            $httpCode = $response->getStatusCode();
            if ($httpCode >= 400) {
                _ppl($response->getBody());
                throw new \SugarApiException("Request failed with status: " . $httpCode, null, null, $httpCode);
            }
            return $response->getBody()->getContents();

    the URL and token are defined in our config_override.php file.

    the body is a json_encode of a PHP array $body = json_encode($json);

    the error is catched when launching the request

Children
No Data