1
rossb
Really stupid php / sql problem
  • 2019/12/9 14:14

  • rossb

  • Just popping in

  • Posts: 77

  • Since: 2006/8/28


Xoops 2.5.9

attempting to fix oledrions bug: "Oledrion\Utility::getEmailsFromGroup" is returning empty

The emails are for the vendor to be notified of sale.

// grp_sold is config var == 1 (Administrator group)
$db XoopsDatabaseFactory::getDatabaseConnection();
$grp_sold_user_ids = []; // Array of user ID's to send emails to
$sql 'SELECT uid FROM ' $db->prefix('groups_users_link') . ' WHERE groupid=' . (int)$grp_sold;
$result_sql $db->query($sql);
if (
$result_sql) {
    while (
$myrow $db->fetchArray($result_sql)) {
        
$grp_sold_user_ids[] = $myrow['uid'];
    }
}
file_put_contents(OLEDRION_GATEWAY_LOG_PATH"implode: " implode(','$grp_sold_user_ids) . "n"FILE_APPEND LOCK_EX);
$sql 'SELECT email FROM ' $db->prefix('users') . ' WHERE uid IN (' implode(','$grp_sold_user_ids) . ')';
$admin_emails = []; 
$result_sql $db->query($sql);
if (
$result_sql) {
    while (
$myrow $db->fetchArray($result_sql)) {
        
$admin_emails[] = $myrow['email'];
    }
}


What I am seeing:
$grp_sold_user_ids tests as array, print_r($grp_sold_user_ids); evaluates to 1
implode(',', $grp_sold_user_ids); // returns null should be 1
implode(',', array(1,2,3); //returns 1,2,3 - OK
implode(',', array(1); //returns 1 - OK

Anyone?
Thanks, Bill

2
rossb
Re: Really stupid php / sql problem
  • 2019/12/11 13:55

  • rossb

  • Just popping in

  • Posts: 77

  • Since: 2006/8/28


Further info:

Appears to be sql errors; despite the fact that queries execute OK from command line.
Previously (code above), ALL sql queries returned no results and, did not appear in transaction log.
And, yes, phpmyadmin reports db as "clean"

Really simple testcase (dump the class):
I researched this and error is commonly caused by:
sql: max_allowed_packet (I use 16M, nowhere near hitting this limit)
sql: wait_timeout, interactive_timeout (I use 28800, nowhere near hitting this limit)
running outa memory:
free -h
total used free shared buffers cached
Mem: 1.9G 1.8G 140M 60K 45M 495M
-/+ buffers/cache: 1.3G 681M
Swap: 3.9G 115M 3.8G

$member_handler xoops_getHandler('member');
file_put_contents(OLEDRION_GATEWAY_LOG_PATH"users_ids: " print_r($user_ids,true) . "n"FILE_APPEND LOCK_EX);
memberHandlerXoopsMemberHandler Object
(
    [
groupHandler:protected] => XoopsGroupHandler Object
        
(
            [
table] => xoops_groups
            
[db] => XoopsMySQLDatabaseProxy Object
                
(
                    [
conn] => mysqli Object
                        
(
                            [
affected_rows] => -1
                            
[client_info] => mysqlnd 5.0.11-dev 20120503 $Id76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
                            [
client_version] => 50011
                            
[connect_errno] => 0
                            
[connect_error] => 
                            [
errno] => 2006
                            
[error] => MySQL server has gone away
                            
[error_list] => Array
                                (
                                    [
0] => Array
                                        (
                                            [
errno] => 2006
                                            
[sqlstate] => HY000
                                            
[error] => MySQL server has gone away
                                        
)

                                    [
1] => Array
                                        (
                                            [
errno] => 2006
                                            
[sqlstate] => HY000
                                            
[error] => MySQL server has gone away
                                        
)

                                )

                            [
field_count] => 0
                            
[host_info] => Localhost via UNIX socket
                            
[info] => Rows matched1  Changed1  Warnings0
                            
[insert_id] => 0
                            
[server_info] => 5.5.60-log
                            
[server_version] => 50560
                            
[stat] => 
                            [
sqlstate] => HY000
                            
[protocol_version] => 10
                            
[thread_id] => 2346
                            
[warning_count] => 0
                        
)

                    [
prefix] => xoops
                    
[logger] => XoopsLogger Object
                        
(
                            [
queries] => Array
                                (
                                    [
0] => Array
                                        (
                                            [
sql] => SET SQL_BIG_SELECTS 1
                                            
[error] => 
                                            [
errno] => 
                                            [
query_time] => 0.00029397010803223
                                        
)

                                    [
1] => Array
                                        (
                                            [
sql] => SELECT FROM xoops_config WHERE (conf_modid '0' AND conf_catid '1'ORDER BY conf_order ASC
                                            
[error] => 
                                            [
errno] => 
                                            [
query_time] => 0.0035851001739502
                                        
)

                                    [
2] => Array
                                        (
                                            [
sql] => SELECT sess_datasess_ip FROM xoops_session WHERE sess_id '3l1hmfs01p6f82lu11uk0tmgk1'
                                            
[error] => 
                                            [
errno] => 
                                            [
query_time] => 0.00056004524230957
                                        
)

                                )

                            [
blocks] => Array
                                (
                                )

                            [
extra] => Array
                                (
                                )

                            [
logstart] => Array
                                (
                                    [
XOOPS] => 1576070405.709
                                    
[XOOPS Boot] => 1576070405.709
                                
)

                            [
logend] => Array
                                (
                                    [
query_time] => 1576070405.7597
                                
)

                            [
errors] => Array
                                (
                                )

                            [
deprecated] => Array
                                (
                                )

                            [
usePopup] => 
                            [
activated] => 
                            [
renderingEnabled] => 1
                        
)

                    [
allowWebChanges] => 1
                
)

        )

    [
userHandler:protected] => XoopsUserHandler Object
        
(
            [
handler] => 
            [
handlers] => Array
                (
                    [
read] => 
                    [
stats] => 
                    [
joint] => 
                    [
write] => 
                    [
sync] => 
                )

            [
table] => xoops_users
            
[keyName] => uid
            
[className] => XoopsUser
            
[identifierName] => uname
            
[field_link] => 
            [
field_object] => 
            [
db] => XoopsMySQLDatabaseProxy Object
                
(
                    [
conn] => mysqli Object
                        
(
                            [
affected_rows] => -1
                            
[client_info] => mysqlnd 5.0.11-dev 20120503 $Id76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
                            [
client_version] => 50011
                            
[connect_errno] => 0
                            
[connect_error] => 
                            [
errno] => 2006
                            
[error] => MySQL server has gone away
                            
[error_list] => Array
                                (
                                    [
0] => Array
                                        (
                                            [
errno] => 2006
                                            
[sqlstate] => HY000
                                            
[error] => MySQL server has gone away
                                        
)

                                    [
1] => Array
                                        (
                                            [
errno] => 2006
                                            
[sqlstate] => HY000
                                            
[error] => MySQL server has gone away
                                        
)

                                    [
2] => Array
                                        (
                                            [
errno] => 2006
                                            
[sqlstate] => HY000
                                            
[error] => MySQL server has gone away
                                        
)

                                )

                            [
field_count] => 0
                            
[host_info] => Localhost via UNIX socket
                            
[info] => Rows matched1  Changed1  Warnings0
                            
[insert_id] => 0
                            
[server_info] => 5.5.60-log
                            
[server_version] => 50560
                            
[stat] => 
                            [
sqlstate] => HY000
                            
[protocol_version] => 10
                            
[thread_id] => 2346
                            
[warning_count] => 0
                        
)

                    [
prefix] => xoops
                    
[logger] => XoopsLogger Object
                        
(
                            [
queries] => Array
                                (
                                    [
0] => Array
                                        (
                                            [
sql] => SET SQL_BIG_SELECTS 1
                                            
[error] => 
                                            [
errno] => 
                                            [
query_time] => 0.00029397010803223
                                        
)

                                    [
1] => Array
                                        (
                                            [
sql] => SELECT FROM xoops_config WHERE (conf_modid '0' AND conf_catid '1'ORDER BY conf_order ASC
                                            
[error] => 
                                            [
errno] => 
                                            [
query_time] => 0.0035851001739502
                                        
)

                                    [
2] => Array
                                        (
                                            [
sql] => SELECT sess_datasess_ip FROM xoops_session WHERE sess_id '3l1hmfs01p6f82lu11uk0tmgk1'
                                            
[error] => 
                                            [
errno] => 
                                            [
query_time] => 0.00056004524230957
                                        
)

                                )

                            [
blocks] => Array
                                (
                                )

                            [
extra] => Array
                                (
                                )

                            [
logstart] => Array
                                (
                                    [
XOOPS] => 1576070405.709
                                    
[XOOPS Boot] => 1576070405.709
                                
)

                            [
logend] => Array
                                (
                                    [
query_time] => 1576070405.7597
                                
)

                            [
errors] => Array
                                (
                                )

                            [
deprecated] => Array
                                (
                                )

                            [
usePopup] => 
                            [
activated] => 
                            [
renderingEnabled] => 1
                        
)

                    [
allowWebChanges] => 1
                
)

        )

    [
membershipHandler:protected] => XoopsMembershipHandler Object
        
(
            [
table] => xoops_groups_users_link
            
[db] => XoopsMySQLDatabaseProxy Object
                
(
                    [
conn] => mysqli Object
                        
(
                            [
affected_rows] => -1
                            
[client_info] => mysqlnd 5.0.11-dev 20120503 $Id76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
                            [
client_version] => 50011
                            
[connect_errno] => 0
                            
[connect_error] => 
                            [
errno] => 2006
                            
[error] => MySQL server has gone away
                            
[error_list] => Array
                                (
                                    [
0] => Array
                                        (
                                            [
errno] => 2006
                                            
[sqlstate] => HY000
                                            
[error] => MySQL server has gone away
                                        
)

                                    [
1] => Array
                                        (
                                            [
errno] => 2006
                                            
[sqlstate] => HY000
                                            
[error] => MySQL server has gone away
                                        
)

                                    [
2] => Array
                                        (
                                            [
errno] => 2006
                                            
[sqlstate] => HY000
                                            
[error] => MySQL server has gone away
                                        
)

                                    [
3] => Array
                                        (
                                            [
errno] => 2006
                                            
[sqlstate] => HY000
                                            
[error] => MySQL server has gone away
                                        
)

                                )

                            [
field_count] => 0
                            
[host_info] => Localhost via UNIX socket
                            
[info] => Rows matched1  Changed1  Warnings0
                            
[insert_id] => 0
                            
[server_info] => 5.5.60-log
                            
[server_version] => 50560
                            
[stat] => 
                            [
sqlstate] => HY000
                            
[protocol_version] => 10
                            
[thread_id] => 2346
                            
[warning_count] => 0
                        
)

                    [
prefix] => xoops
                    
[logger] => XoopsLogger Object
                        
(
                            [
queries] => Array
                                (
                                    [
0] => Array
                                        (
                                            [
sql] => SET SQL_BIG_SELECTS 1
                                            
[error] => 
                                            [
errno] => 
                                            [
query_time] => 0.00029397010803223
                                        
)

                                    [
1] => Array
                                        (
                                            [
sql] => SELECT FROM xoops_config WHERE (conf_modid '0' AND conf_catid '1'ORDER BY conf_order ASC
                                            
[error] => 
                                            [
errno] => 
                                            [
query_time] => 0.0035851001739502
                                        
)

                                    [
2] => Array
                                        (
                                            [
sql] => SELECT sess_datasess_ip FROM xoops_session WHERE sess_id '3l1hmfs01p6f82lu11uk0tmgk1'
                                            
[error] => 
                                            [
errno] => 
                                            [
query_time] => 0.00056004524230957
                                        
)

                                )

                            [
blocks] => Array
                                (
                                )

                            [
extra] => Array
                                (
                                )

                            [
logstart] => Array
                                (
                                    [
XOOPS] => 1576070405.709
                                    
[XOOPS Boot] => 1576070405.709
                                
)

                            [
logend] => Array
                                (
                                    [
query_time] => 1576070405.7597
                                
)

                            [
errors] => Array
                                (
                                )

                            [
deprecated] => Array
                                (
                                )

                            [
usePopup] => 
                            [
activated] => 
                            [
renderingEnabled] => 1
                        
)

                    [
allowWebChanges] => 1
                
)

        )

    [
membersWorkingList:protected] => Array
        (
        )

)


What I don't get is why simply instantiating $member_handler = xoops_getHandler('member'); results in errors.

I also have issues with new members being unable to register - keeps returning to basic registration page.

I have spent way too much time on this and am considering giving up on oledrion and finding a non-xoops e-commerce solution.

Anyone care to assist debugging? May involve sshing in.

Regards;
Bill

3
rossb
Re: Really stupid php / sql problem
  • 2019/12/11 15:48

  • rossb

  • Just popping in

  • Posts: 77

  • Since: 2006/8/28


Here's the EXACT code that is failing:

public static function getUsersFromGroup($groupId)
    {
        
/** @var XoopsMemberHandler $memberHandler */
        
$memberHandler xoops_getHandler('member');
        
file_put_contents(OLEDRION_GATEWAY_LOG_PATH"memberHandler: " print_r($memberHandler,true) . "n"FILE_APPEND LOCK_EX);
        
$users         $memberHandler->getUsersByGroup($groupIdtrue);
        
file_put_contents(OLEDRION_GATEWAY_LOG_PATH"users: " print_r($users,true) . "n"FILE_APPEND LOCK_EX);
        return 
$users;
    }

    
/**
     * Retourne la liste des emails des utilisateurs membres d'un groupe
     *
     * @param $groupId
     * @return array Emails list
     * @internal param int $group_id Group's number
     */
    
public static function getEmailsFromGroup($groupId)
    {
        
$ret = [];
        
file_put_contents(OLEDRION_GATEWAY_LOG_PATH"groupId: " print_r($groupId) . "n"FILE_APPEND LOCK_EX);
        
$member_handler xoops_getHandler('member');
        
$user_ids = static::getUsersFromGroup($groupId);
        
file_put_contents(OLEDRION_GATEWAY_LOG_PATH"users_ids: " print_r($user_ids,true) . "n"FILE_APPEND LOCK_EX);
        foreach (
$user_ids as $user_id) {
            
//$user = $member_handler->getUser($user_id);
            
$user $member_handler->getUsers(nulltrue);
            
$ret[] = $user->getVar('email');
        }

        
file_put_contents(OLEDRION_GATEWAY_LOG_PATH"ret: " .  print_r($ret,true) . "n"FILE_APPEND LOCK_EX);
        return 
$ret;
    }

4
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.

5
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....

6
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...

7
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.

8
rossb
Re: Really NOT a stupid php / sql problem
  • 2019/12/14 11:44

  • rossb

  • Just popping in

  • Posts: 77

  • Since: 2006/8/28


I caused the problem in the first place. No longer fork is the solution I chose for oledrion-2.35_RC2 which I will be releasing a patch set for after testing is complete.

Login

Who's Online

153 user(s) are online (101 user(s) are browsing Support Forums)


Members: 0


Guests: 153


more...

Donat-O-Meter

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

Latest GitHub Commits