1701
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
);



1702
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();



1703
geekwright
Re: Really NOT a stupid php / sql problem

This is an interesting problem. I am not an expect on oledrion, nor multi-thread PHP, but I can see the problem.

I started with the current master of the code here:
https://github.com/mambax7/oledrion.git

I did a quick scan of the code to see this:
grep -r pcntl *
class/
Gateways/Paypal/PaypalGateway.php:                    $pid pcntl_fork();


The takeaway from this is that there is only one 'pcntl' call in the code, and that is a fork. Nothing is waiting or watching for another fork, i.e. a pcntl_wait() call.

The botched mysqli connection is due to the fact that the process was forked, and the first fork that exits closes the database connection, leaving all other forks with a dead database object.

I am not sure how things ended up in this state. It is possible that the mysql and mysqli extensions behave differently in this circumstance. It is also possible something important is just missing.

It will take more research to get a handle on this and determine a plan of action. But, this is not a stupid problem. It is a very interesting problem.



1704
alain01
Re: Which editor do you use ?
  • 2019/12/13 0:52

  • alain01

  • Just can't stay away

  • Posts: 530

  • Since: 2003/6/20


Quote:

geekwright wrote:
The first thing that will happen is the program will build an index of all the files in that directory. From that index, it will know in most cases all the functions, classes, and variables by type and signature. That enables auto-completion, parameter hints and easy access to documentation blocks.
Haaaaa, ok, thanks for this very usefull detail



1705
geekwright
Re: Which editor do you use ?

Quote:

alain01 wrote:
...
Is there any snippets, extension for XOOPS, for
PhPstorm and Visual Studio Code ? (didnt find)

(XMF words, xoops smarty) ?
...


With VSCode, you will want to install the PHP IntelliSense extension. (It will offer useful extensions when you open a file type for the first time,)

With both PHPStorm and VSCode (and Eclipse as I recall,) you will open a directory (i.e. your XoopsCore25 clone.) The first thing that will happen is the program will build an index of all the files in that directory. From that index, it will know in most cases all the functions, classes, and variables by type and signature. That enables auto-completion, parameter hints and easy access to documentation blocks. Those features are one of the reasons for making the move from simple editors to integrated development environments (IDE)



1706
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



1707
rossb
Progress: Re: Really stupid php / sql problem
  • 2019/12/12 21:56

  • rossb

  • Just popping in

  • Posts: 77

  • Since: 2006/8/28


OK; starting to make sense.

Code forks to return to return paypal callback quickly (they spec 30 seconds max). Parent returns immediately, child (time consuming work) does db updates, sends confirmation emails, etc.

apparently, when the parent exits, db connection is closed after an indeterminate time. This causes a race condition where child may or may not have a db connection.

It is a known "issue":
https://www.php.net/manual/en/function.pcntl-fork.php#70721

Starting a new thread regarding how to get a new database connection within the child process.

I'll leave it to the reader to decide whether it is a stupid problem or coder...



1708
rossb
Re: Really stupid php / sql problem
  • 2019/12/12 20:04

  • rossb

  • Just popping in

  • Posts: 77

  • Since: 2006/8/28


Thanks; caught that one already. Not the issue.

Issue is: code is called out of site context by paypal callback.
...and, it forks to offload processing.

All attempts to use database fail: "MySQL server has gone away", even though db object exists.

have run outa theories....



1709
zyspec
Re: Which editor do you use ?
  • 2019/12/12 17:26

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


I typically use Eclipse PDT.... I like it because:
  • there are versions for both Windows and Linux - so it's easy to switch between my various systems.
  • easy to create/modify coding styles (modified PSRxx, etc)
  • it's free
  • easily "jump-to" referenced functions
  • customized syntax highlighting for PHP, JS, XML, MySQL, etc
  • refactoring
  • GitHub integration (easy to pull/push/commit/etc)
  • Composer support
  • Good build/run tools
  • Eclipse community support
  • Bug/Issue tracking integration
  • code completion


  • The one drawback is lack of Smarty syntax support - there's a plugin for it but it's old & doesn't work well.

    I also use Notepad++ for a quick editor when needed. PHPStorm is a good product too but I haven't found enough difference/advantage to it that would cause me to change from Eclipse (and pay the money).



    1710
    zyspec
    Re: Really stupid php / sql problem
    • 2019/12/12 14:58

    • zyspec

    • Module Developer

    • Posts: 1095

    • Since: 2004/9/21


    One thing is it appears that the print_r() in the getEmailsFromGroup() is missing the 'true' parameter in:
    file_put_contents(OLEDRION_GATEWAY_LOG_PATH"groupId: " print_r($groupId) . "n"FILE_APPEND LOCK_EX);


    should be:
    file_put_contents(OLEDRION_GATEWAY_LOG_PATH"groupId: " print_r($groupIdtrue) . "n"FILE_APPEND LOCK_EX);


    don't know if that's the only issue but looks like it should be corrected.




    TopTop
    « 1 ... 168 169 170 (171) 172 173 174 ... 29425 »



    Login

    Who's Online

    767 user(s) are online (536 user(s) are browsing Support Forums)


    Members: 0


    Guests: 767


    more...

    Donat-O-Meter

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

    Latest GitHub Commits