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 

Fullscreen
1
src\Security\HttpClient\ExternalResourceClient.php
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

(but not for sure).

Any help, suggestion or whatever is welcome.

Fred

  • Hi Frederic,

    Can you please check if on the 1st line of your custom file if there is an space or special character there.

    Rodrigo Manara

    Sr. Developer

  • Hi

    tahnk you for your feedback.No, as far as I look at it, nothing weird in my custom file.

  • perhaps a sample of your code?

    Rodrigo Manara

    Sr. Developer

  • Here is our CALL method  

     

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    // 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();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    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

  • Got it ; our error was to set the timeout to 0.

    We were thinking that 0 means no timeout at all, instead of what it means I won't wait any seconds :-).

    So obviously our query failed because it takes more then 0 second.

    Thank you for your support

  • Make sense, I had something similar where I did not set the timeout correctly and it was giving an strange error , so I had to change the timeout value to something over 3 secs. 

    Rodrigo Manara

    Sr. Developer