xoops forums

rossb

Just popping in
Posted on: 12/12 22:01
rossb
rossb (Show more)
Just popping in
Posts: 66
Since: 2006/8/28
#1

How to create a new xoopsDB connection - from scratch

Hi;

I am using pcntl_fork and ran into this issue:
https://www.php.net/manual/en/function.pcntl-fork.php#70721
- no database connection in child, after parent exits.

so; I need a new db connection and am not sure how to do so properly.

something along lines of:
$xoopsDB = new XoopsMySQLDatabase();
$xoopsDB->connect();


just need to know the "proper way"

Anyone?
Thanks;
Bill

zyspec

Module Developer
Posted on: 12/13 3:00
zyspec
zyspec (Show more)
Module Developer
Posts: 1077
Since: 2004/9/21
#2

Re: How to create a new xoopsDB connection - from scratch

Try
$db     XoopsDatabaseFactory::getDatabaseConnection();

geekwright

Quite a regular
Posted on: 12/13 3:51
geekwright
geekwright (Show more)
Quite a regular
Posts: 302
Since: 2010/10/15
#3

Re: How to create a new xoopsDB connection - from scratch

The clean way would be to pcntl_wait() for the child to end.

The database expects to be a singleton -- only one at a time.

The part that is dropped is the low level mysqli connection stored in the conn property in XoopsMySQLDatabase.

I cannot guarantee this, but it would look something like this:
$xoopsDB->conn  = new mysqli(
    
XOOPS_DB_HOST
    
XOOPS_DB_USER
    
XOOPS_DB_PASS,
    
XOOPS_DB_NAME
);

rossb

Just popping in
Posted on: 12/13 18:06
rossb
rossb (Show more)
Just popping in
Posts: 66
Since: 2006/8/28
#4

Re: How to create a new xoopsDB connection - from scratch

Thanks geekwright.

Got it working.
Needed:
$xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); -without this, hangs
$xoopsDB->conn = new mysqli( XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, XOOPS_DB_NAME );

and, after all the hassle, using pcntl_fork, shaved 200milliseconds off return to paypal. Max observed transaction time is < 2 seconds; paypal requires < 30 seconds.

hardly worth it; so paypal callback is now single process / thread.

...B