ID: 47712 User updated by: ninzya at inbox dot lv Reported By: ninzya at inbox dot lv Status: Open Bug Type: Scripting Engine problem Operating System: Windows XP PHP Version: 5.3.0beta1 New Comment:
I got a little bit closer to the problem. Here's what happens. See this script: // load page $sql ='SELECT id, ' .implode( ', ', $properties) .' FROM ' .TAB_PREF .'pages WHERE node_id =' .$Db->escape( $nodeId, 'UINT').' AND alt_name =' .$Db->escape( $pageAlt, 'STRING') .' LIMIT 0, 1;'; if(( $row =$Db->queryFirst( $sql)) ===null) throw new Exception( 'NOT_FOUND'); if( $row['id'] ===null) {// THIS IS WHERE YOU SHOULD LOOK AT trigger_error( 'Got NULL!', E_USER_WARNING); trigger_error( 'SQL: ' .$sql, E_USER_WARNING); ob_start(); var_dump( $row); trigger_error( ob_get_clean(), E_USER_WARNING); die(); } As you can see, i am testing if $row['id'] is null (this is unexpected situation when this field becomes null, it's an auto column and at this step i expect successfully fetched row), and if it is NULL, then i wish to see the debug info for the contents of $row and overall "what's going on". Now here is the error log when this unexpected situation is being RANDOMLY triggered during stress test: [20-Mar-2009 14:20:37] PHP Warning: Got NULL! in D:\...\pages.php on line 93 [20-Mar-2009 14:20:37] PHP Warning: SQL: SELECT id, `title`, `keywords`, `descr`, `template_id` FROM pages WHERE node_id =11 AND alt_name ='welcome' LIMIT 0, 1; in D:\...\pages.php on line 94 [20-Mar-2009 14:20:37] PHP Warning: array(5) { ["id"]=> string(6) "SHARED" ["title"]=> string(12) "My test page" ["keywords"]=> string(6) "asdasd" ["descr"]=> string(6) "asdasd" ["template_id"]=> string(4) "8567" } in D:\...\pages.php on line 97 I don't know how to explain this. I guess this is mysqlnd failing this bad. Previous Comments: ------------------------------------------------------------------------ [2009-03-20 12:12:15] ninzya at inbox dot lv Every mentioned error/warning occurs randomly. It is not possible to trigger these warnings (especially first) during each request, something related to memory fails i think, or stack is being corrupted or something. I was investigating this problem for past day and i found this. Take a look at the following script: <?php function throw_exc() { throw new Exception('TEST_EXCEPTION'); } class Test { public function __construct() { echo 'Constr' ."\n"; } public function __destruct() { echo 'Destr' ."\n"; } } try { $T =new Test( throw_exc()); } catch( Exception $e) { echo 'Exception: ' .$e->getMessage(); } ?> Execution of this script produces: Destr Exception: TEST_EXCEPTION Where it should produce only this part: Exception: TEST_EXCEPTION As you can see, destructor is being called, where it shouldn't be. I will make a temporary work around for this situation and investigate further, because i guess this is not the problem that has caused first warning/error message i mentioned above. ------------------------------------------------------------------------ [2009-03-19 00:30:38] scott...@php.net Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. We need an actual reproduce script we can use, I took your small script and ran it under 5.3.0 without issue. I'm guessing our errors probably all stem from the same issue, if step 1 or 3 happen then 2 and 4 would be expected due to a lack of database connection. ------------------------------------------------------------------------ [2009-03-19 00:02:49] ninzya at inbox dot lv Description: ------------ My configuration is Windows XP, Apache 2.2.11.0, PHP 5.3.0beta1, i'm coding a framework and periodically i am performing stress tests with apache's ab.exe. Once my framework has become quite processive (lotsa operations involved in request processing), there started to appear unexpected PHP errors/warning in a PHP error log file. For details see reproduce code. Reproduce code: --------------- I was performing periodical stress testing by running "ab.exe -c 30 -n 10000 http://..../myframeworkpage.php". Sometimes PHP error log had been empty after 10000 req. stress testing, sometimes there were some errors/warning (from 1 to 10 usually), and these errors were reporting absurd things happening around. What i noticed, is that under heavy load PHP manages to implicitly reset some variables to NULL value, or "lose value", which results in NULL value. Here are some of those errors and my assumptions for those errors: 1) "PHP Notice: Use of undefined constant - assumed '' in ... on line 25", where line #25 is "$Db->connect( DB_PERS, DB_HOST, DB_PORT, DB_USER, DB_PASS);". This is definately failure of PHP. 2) "PHP Fatal error: Call to a member function fetch() on a non-object in ... on line 611" where line #611 is "while( $this->Db->fetch( $this->query));". Please note that this cycle is contained within __destruct() method (probably $Db property is being destroyed too soon when php execution ends, but i assume it was also implicitly reset to NULL). Definately failure of PHP. 3) "PHP Warning: mysql_pconnect(): Access denied for user 'root'@'localhost' (using password: NO) in ... on line 163" where line #163 is "$link =mysql_pconnect( $host .':' .$port, $user, $pass, $clientFlags);" and $pass was never set to null or whatsoever (it contains string password, always). I could assume here failure of MySQL server. 4) "PHP Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in ... on line 483" where line #483 is "return '\'' .mysql_real_escape_string( $data, $this->link) .'\'';" and i'm 100% sure $link property is not null at the step, when call to mysql_real_escape_string is issued. I could assume here failure of MySQL server, which resulted in resource to become null (which is also absurd). 5) "PHP Warning: Invalid argument supplied for foreach() in ... on line 414" where line #414 is "foreach( $patchset as $blockId =>$fill)", and $patchset is a reference to an array, always. Definately failure of PHP. And much more such examples, which all say the same thing - "i got the null value, what the hell?". I tried to make some stress testings for such code as: class X { public function __construct() { } public function __destruct() { } public function test() { } public function Y() { return new Y( $this); } } class Y { protected $X; public function __construct( $X) { $this->X =$X; } public function __destruct() { $this->X->test(); } } $X =new X(); $Y =$X->Y(); $C =$X->Y(); $A =$X->Y(); but it executed successfully with no errors. I tried 300000 requests, everything went fine. But, when i stress-test my framework, PHP *sometimes* acts weird. So far i failed to find compact reproduction code for this issue. Expected result: ---------------- I expect to see no warnings described in "Reproduce code" section. Actual result: -------------- PHP under heavy load implicitly resets random variable's value to NULL or "looses" random variable's value, which results in assignment of NULL value to that variable. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47712&edit=1