Jump to content

How to reconnect default database connection?


Recommended Posts

Hello, please help me with next issue

Let's imagine i have custom script which interacting with WHMCS... ( WHMCS 7.1.2 )

 

<?php

define('CLIENTAREA',                true);
define('WHMCS_ROOT_DIR',            dirname(dirname(__FILE__)));

require WHMCS_ROOT_DIR . '/init.php';

$result = \localApi('GetOrders', array('userid' => $user_id, 'id' => $order_id),  'administrator');

long_running_function(); // runing about 10 minutes

$result = \localApi('GetOrders', array('userid' => $user_id, 'id' => $order_id),  'administrator');

?>

 

It's abstract code to reproduce issue. Let's see what's happened. First call of "LocalApi" return "success" as expected

But after "long_running_function" ends then second call of "LocalApi" return error with message "No matching admin user found"

And console output says me next: "# PHP Warning:  mysql_fetch_array() expects parameter to be resource, boolean was given. in /home/whmcs/web/public_html/includes/dbcompatfunctions.php on line 0"

It's seems to be because mysql lost default connection after long time of waiting and "localApi" function can't get id of provided user. So how i can reestablish connection to continue use of "localApi" function?

Using of before second call of localApi  Capsule::connection()->reconnect(); has no effect

Link to comment
Share on other sites

5 hours ago, steven99 said:

You can try Capsule::connection()->getPdo() IIRC to see if that will do a reconnect as it seems reconnect doesn't work but you will want to close the pdo before doing any other capsule queries as the pdo takes over and expects to be used from what I have seen. 

 

On 3/19/2019 at 8:32 PM, Gricenko Mihail said:

Capsule::connection()->reconnect();

 

Working with Capsule::table() queries. But it's don't take any effect with \LocalApi function. I think \LocalApi code is not used Capsule:: inside

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated