1
rossb
How to create a new xoopsDB connection - from scratch
  • 2019/12/12 22:01

  • rossb

  • Just popping in

  • Posts: 77

  • Since: 2006/8/28


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

2
zyspec
Re: How to create a new xoopsDB connection - from scratch
  • 2019/12/13 3:00

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


Try
$db     XoopsDatabaseFactory::getDatabaseConnection();

3
geekwright
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
);

4
rossb
Re: How to create a new xoopsDB connection - from scratch
  • 2019/12/13 18:06

  • rossb

  • Just popping in

  • Posts: 77

  • Since: 2006/8/28


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

Login

Who's Online

369 user(s) are online (273 user(s) are browsing Support Forums)


Members: 0


Guests: 369


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits