Compare commits

...
Author SHA1 Message Date
Johannes Schlüter a83cab45d8 tag 5.3.2RC1 2009-12-22 22:04:16 +00:00
Johannes Schlüter f25081724b PHP 5.3.2RC1 2009-12-22 22:02:50 +00:00
Johannes Schlüter 8d662076c4 release branch 5.3.2 2009-12-22 21:43:59 +00:00
Johannes Schlüter 5927cec714 Wrap at 80 chars 2009-12-22 21:17:58 +00:00
Johannes Schlüter c764995c8e install mysqlnd headers to allow shared build of extensions 2009-12-22 19:30:09 +00:00
Andrey Hristov c95fa280ed Fix double calls to free_contents if the connection cannot be
opened. mysqlnd have no probs, external code should not have too.
In any case, double call is not needed.
2009-12-22 17:44:42 +00:00
Andrey Hristov e1251edc16 move state setting to the right place, in mysqlnd_init, no more
in mysqlnd::connect
2009-12-22 17:31:31 +00:00
Pierre Joye 9309f2bf64 - fix build and warning (introduced by my last commit) 2009-12-22 14:57:57 +00:00
Jani Taskinen 294401cfa0 - Fixed bug #50517 (EXTRA_LDFLAGS polluted by wrong entries)
# Until someone shows me use case for LDFLAGS, this is gone.
# This was wrong place to import it anyway.
2009-12-22 09:57:19 +00:00
Moriyoshi Koizumi 7d9a7dbad6 - Fix bug #46478 (htmlentities() uses obsolete mapping table for character
entity references)
2009-12-22 05:50:34 +00:00
Ilia Alshanetsky 800519fcbb Fixed bug #45599 (strip_tags() truncates rest of string with invalid attribute). 2009-12-22 02:04:12 +00:00
Derick Rethans bfa1c91d9b - Updated to version 2009.20 (2009t) 2009-12-21 20:46:12 +00:00
Sriram Natarajan 20cd29d0a2 Fixed bug #50540 (Crash within ldap_first_reference function) 2009-12-21 20:39:48 +00:00
Stanislav Malyshev baaec77e78 clean up normalizer code 2009-12-21 20:12:46 +00:00
Andrey Hristov 41ac91aecf Move this function to MYSQLND_NET as it works on the
php stream
2009-12-21 16:52:10 +00:00
Andrey Hristov ce349e3540 magic numbers to macros 2009-12-21 16:17:31 +00:00
Andrey Hristov b4477669b4 Move compression and decompression code to separate functions
which can be overloaded on purpose.
2009-12-21 16:09:13 +00:00
Jani Taskinen 4bba459d8f - Sync (and KEEP it synced!) 2009-12-21 15:44:58 +00:00
Jani Taskinen d0a956c2b7 - Tune the fix for bug #50508 and make it work with MacOSX, bug #50541. 2009-12-21 15:22:40 +00:00
Felipe Pena e83e52eba1 - New tests 2009-12-20 22:04:55 +00:00
Stanislav Malyshev ae70213177 Fixed bug #50196 stream_copy_to_stream() produces warning when source is not file 2009-12-19 01:15:30 +00:00
Stanislav Malyshev 0401c6ca2d fix bug #50196 2009-12-19 01:13:33 +00:00
Stanislav Malyshev e665b0955a Fixed bug #50394 (Reference argument converted to value in __call) 2009-12-18 19:20:33 +00:00
Stanislav Malyshev fc1e17ee76 fix regression bug #50394: Reference argument converted to value in __call 2009-12-18 19:12:11 +00:00
Jani Taskinen b7608c91e4 touch 2009-12-18 12:48:59 +00:00
Jani Taskinen 52f83608d8 - Fixed bug #50508 (compile fails: Conflicting HEADER type declarations)
# NEVER ever include nameser_compat.h, it's included in various ways in different OSes by nameser.h if needed
2009-12-18 11:02:07 +00:00
Pierre Joye dea1d412e1 - [DOC] add INTERNALDATE to imap_append (will merge to trunk later) 2009-12-17 17:28:26 +00:00
Jani Taskinen 215dd9d02c - These are 2 separate sections.. 2009-12-17 16:10:53 +00:00
Ulf Wendel e2a2205a58 Test for what Andrey has found with 16M packets 2009-12-17 14:15:28 +00:00
Andrey Hristov 028bd4ba02 refactoring : move more network related functions to
mysqlnd_net.c . Now communication is split on two levels:
- logical (functions send and receive)
- physical (functions network_read and network_write)
2009-12-17 13:29:46 +00:00
Andrey Hristov 22528b14a4 During refactoring of the function mysqlnd_stream_write_w_header() it was
found that there is a bug in the way the data is sent, although a very rare
one which will only affect very large queries which have length 16777214. The
communication will hang. A way to test it is to execute the following:
./php -r '$c=mysqli_connect("127.0.0.1","root","root","test");
$q="insert into test.tblob values(\"".str_repeat("a",256*256*256-1-34)."\")";
$c->query($q);'
2009-12-17 12:30:58 +00:00
Sriram Natarajan 4e06ca007f - Fix NEWS for bug #50496
# Update NEWS to keep resolved bugs in decreasing order (Christopher Jones)
2009-12-16 21:33:20 +00:00
Sriram Natarajan cbc6619fe3 - Fixed bug #50496 (Use of <stdbool.h> is valid only in a c99 compilation environment.) 2009-12-16 20:49:08 +00:00
Andrey Hristov d233b0b2af call free_contents in every case, in case something is not freed
by the calling code
2009-12-16 14:38:30 +00:00
Andrey Hristov a1ef2d9fb3 Remove unneeded dereferences
(oops, committed the trunk changes from a wrong directory, which splitted
this commit).
2009-12-16 14:06:09 +00:00
Andrey Hristov b3546d1b5e move MYSQLND_NET code to a separate file.
mysqlnd_wireprotocol is about the protocol not the transport
layer
2009-12-16 12:59:38 +00:00
Pierre Joye 6ec6a9d62e - add a test case and update the skip clause 2009-12-16 10:09:34 +00:00
Andrey Hristov 5e1c95fda4 remove duplicated code 2009-12-15 17:39:30 +00:00
Andrey Hristov c101f7f542 Move code out of mysqlnd_conn::connect to mysqlnd_net::connect.
Thus mysqlnd_conn::connect() does less of what it should not do - think
about the transport level.
2009-12-15 17:33:06 +00:00
Andrey Hristov 70690e1163 remove C++ comments 2009-12-15 14:48:24 +00:00
Andrey Hristov 523471f7e8 export this function 2009-12-15 14:26:24 +00:00
Andrey Hristov 0371ef1070 refactor: move code that belongs to MYSQLND_NET out of MYSQLND 2009-12-15 13:13:51 +00:00
Ilia Alshanetsky d0f6848e66 Fixed bu #50392 (date_create_from_format() enforces 6 digits for 'u' format character) 2009-12-15 12:34:12 +00:00
Jani Taskinen 4e10081f8f - Make $sbindir be usable in C code as well (like $bindir and co.) 2009-12-15 11:17:47 +00:00
Jani Taskinen def4e7c0e6 - Allow using $sbindir as well 2009-12-15 10:55:27 +00:00
Felipe Pena c00a91a024 - Added SKIPIF 2009-12-15 00:37:43 +00:00
Felipe Pena 286f36e702 - Fixed memory leak when E_STRICT message is getted 2009-12-14 21:44:56 +00:00
Jani Taskinen 9f210d53cc - Fix test 2009-12-14 09:42:55 +00:00
Jani Taskinen 16dbf3060b - Fix test 2009-12-14 09:26:49 +00:00
Pierrick Charron c2fccc1606 - Fixed bug #50469 (Fixed typo in imagepsencodefont error string). 2009-12-14 04:09:18 +00:00
Pierrick Charron 7d4643193d - Fixed bug #50458 (PDO::FETCH_FUNC fails with Closures) 2009-12-14 03:44:33 +00:00
Felipe Pena 35ad330849 - Improved the bug#49174 entry summary 2009-12-13 20:51:15 +00:00
Felipe Pena 85f96a8132 - Completing the phrase 2009-12-13 20:04:44 +00:00
Felipe Pena 93a406ac9c - Fixed bug #49174 (crash on queryString set) 2009-12-13 19:53:44 +00:00
Felipe Pena 4411621217 - Fixed bug #50209 (Compiling with libedit cannot find readline.h)
(patch by tcallawa at redhat dot com)
2009-12-13 17:06:47 +00:00
Felipe Pena eb3eea2669 - Fixed tests for when running using libedit 2009-12-13 16:53:24 +00:00
Ilia Alshanetsky d56c1fdf14 Fixed bug #50451 (http wrapper breaks on 2048 char long headers)
# Improvement on the fix for bug #49851
2009-12-13 15:44:22 +00:00
Felipe Pena 81ad353ec2 - Fixed bug #50464 (declare encoding doesn't work with)
# The bug (BC) only happens in this branch.
2009-12-13 15:18:58 +00:00
Felipe Pena 5eae703705 - Fixed bug #50445 (PDO-ODBC stored procedure call from Solaris 64-bit causes seg fault).
(Original patch by davbrown4 at yahoo dot com)
2009-12-11 22:30:46 +00:00
Pierre Joye af206a90ae - fix build, come on, it is not that hard to test before commit, is it? 2009-12-11 16:35:42 +00:00
Pierre Joye a2cf15fcc6 - #50334, add sha support for VC6 too, not merged in trunk as we don't support vc6 there 2009-12-11 16:07:57 +00:00
Pierre Joye 560ed89bfb - #50334, use our own implementations of stpncpy and mempcy, avoiding weird behaviors on certain platforms like solaris 2009-12-11 15:57:01 +00:00
Jani Taskinen b9ac76c51c - Fix test 2009-12-11 15:38:15 +00:00
Jani Taskinen 70a2b56337 fix test 2009-12-11 15:06:50 +00:00
Andrey Hristov 13c8bba00a Make MYSQLND_NET dynamically allocated structure with allocator
and deallocator. More member functions will come.
2009-12-11 11:58:57 +00:00
Jani Taskinen 35a4d5831b Fix test 2009-12-11 10:55:56 +00:00
Andrey Hristov a9295f0343 remove stale comment 2009-12-11 10:21:34 +00:00
Andrey Hristov 0c7a9b8010 Move two functions which are used in the extension as methods of
the connection. Two functions less in the global namespace.
2009-12-11 10:18:00 +00:00
Jani Taskinen 03a47e9b03 - Fix problem with SKIPIF failing to skip in some cases (deprecated warnings f.e.) 2009-12-11 07:34:06 +00:00
Christopher Jones 1aebd220f8 Add new 'fetch' test and make several small test fixes 2009-12-10 19:07:08 +00:00
Christopher Jones e435285b39 Remove text recently merged to online doc 2009-12-10 17:28:19 +00:00
Pierre Joye f59f7a3f49 - #50334, add define on win as well 2009-12-10 14:08:19 +00:00
Andrey Hristov a633de0020 bump version number 2009-12-10 11:59:14 +00:00
Andrey Hristov 00d76a8445 Add plugin storage for MYSQLND_STMT too 2009-12-10 11:18:05 +00:00
Andrey Hristov c8c250df80 Fix pdo build, forgot to remove the zval caching from pdo-mysql 2009-12-10 09:35:10 +00:00
Jani Taskinen 01eae78ec3 - not needed anymore 2009-12-10 09:23:06 +00:00
Jani Taskinen 5e7fddab93 - Fix test mess (testing the deprecated ini option is pointless when using the func does same thing) 2009-12-10 09:22:54 +00:00
Ilia Alshanetsky 47b3371122 Fixed bug #49851 (http wrapper breaks on 1024 char long headers). 2009-12-10 03:23:05 +00:00
Pierre Joye 7179910573 - [DOC] expose MPIR version when mpir is used instead of gmp 2009-12-10 02:25:47 +00:00
Andrey Hristov 06a417b6a9 Remove stub code which never actually was used for anything.
Things like this can be built on top of the core.
2009-12-09 20:38:11 +00:00
Andrey Hristov 6f598e62ff Remove the zval caching from mysqlnd. It was disabled versions ago
due to problems on windows, which were not debugged. Better have 
code that is disabled not in the core.
2009-12-09 20:21:05 +00:00
Andrey Hristov d8a8d823ce Fix compilation warnings 2009-12-09 18:11:03 +00:00
Pierre Joye 8d58b31495 - #50334, fix build for platform without endian.h (like solaris) 2009-12-09 17:40:19 +00:00
Andrey Hristov 4d2735007d Remove disabled code - threaded fetching. This can be implemented
on a upper level and by offloading it we reduce the complexity of
the core.
2009-12-09 16:57:03 +00:00
Jani Taskinen 64fb1fca1f - Add one test from HEAD 2009-12-09 13:25:10 +00:00
Ulf Wendel 671ebe958a Adapting tests to accept actual behaviour found in 5.2, 5.3 and 6.0. The behaviour is wrong according to the documentation: mysqli_connect_error() should return an empty string (not NULL), if there is no error. However, changing this would break BC and most users will not notice the difference between NULL and empty string anyway. 2009-12-09 12:06:10 +00:00
Pierre Joye bf377f6aab - #50334, add missing file 2009-12-09 10:39:03 +00:00
Jani Taskinen 6dff9d7632 FIFO 2009-12-09 10:15:34 +00:00
Pierre Joye 77afccc28c - #50334, add CRYPT_SHA* constants and tests [DOC] 2009-12-09 01:43:23 +00:00
Pierre Joye 6a9f96f267 - update 2009-12-09 00:35:30 +00:00
Pierre Joye 2e6c08b289 - drop non used code and fix warning 2009-12-09 00:32:14 +00:00
Pierre Joye 9001b4036a - #50334, crypt ignores sha512 and add support for sha256/512 to php's crypt [DOC] 2009-12-09 00:20:14 +00:00
William Martin d06e06007a Backported 5.3 tests to 5.2 and added more RecursiveIteratorIterator tests 2009-12-08 19:51:56 +00:00
Jani Taskinen c4819e9ff3 MFH: static before const 2009-12-08 17:30:22 +00:00
Ilia Alshanetsky 752b9fde5a Upgraded to Sqlite 3.6.21 2009-12-08 13:24:27 +00:00
Dmitry Stogov 76c445dd73 - Forgotten patch for trunk
- Fixed stdin filename in error messages
2009-12-08 10:16:38 +00:00
Jani Taskinen 0e218d3512 FIFO 2009-12-08 06:19:56 +00:00
Felipe Pena a94558c855 - Added MAKE_COPY_ZVAL(ppzv, pzv) macro 2009-12-08 01:57:37 +00:00
Stanislav Malyshev a9044795da ouch, that ZTS 2009-12-08 01:57:16 +00:00
Stanislav Malyshev 327cf380e8 win32 should have different test 2009-12-08 01:52:57 +00:00
Felipe Pena da22aa9aad - Fixed ZTS build 2009-12-08 01:51:34 +00:00
Stanislav Malyshev 90df6f2ca2 add "no params" check 2009-12-08 01:44:15 +00:00
Stanislav Malyshev 7beb1af8de add realpath cache inspect functions 2009-12-08 01:35:08 +00:00
Moriyoshi Koizumi 413196c574 - Take account of surrogate pairs. 2009-12-07 15:41:43 +00:00
Ilia Alshanetsky 2be6de0a50 Added FILTER_FLAG_STRIP_BACKTICK option to the filter extension. 2009-12-07 13:43:44 +00:00
Dmitry Stogov 6ab5f53d52 Fixed bug #49866 (Making reference on string offsets crashes PHP) 2009-12-07 08:47:18 +00:00
Dmitry Stogov 7a96fdff4c Fixed bug #50351 (performance regression handling objects, ten times slower in 5.3 than in 5.2. foreach statement should not initiate GC) 2009-12-07 08:14:48 +00:00
Jani Taskinen 4963d99213 - Fix NEWS 2009-12-07 07:30:41 +00:00
Pierrick Charron 99ba48dc60 Fixed bug #50323 (Allow use of ; in values via ;; in PDO DSN even in the middle of a string). 2009-12-06 21:32:58 +00:00
Ilia Alshanetsky bf550fe8da Fixed bug #50323 (Allow use of ; in values via ;; in PDO DSN). 2009-12-06 19:34:12 +00:00
Felipe Pena 30188d3c58 - Fixed bug #50162 (Memory leak when fetching timestamp column from Oracle database)
- Fixed bug #34852 (Failure in odbc_exec() using oracle-supplied odbc driver) (patch by tim dot tassonis at trivadis dot com)
2009-12-06 18:53:16 +00:00
Sriram Natarajan 77895623dc BFN 2009-12-06 16:43:46 +00:00
Felipe Pena 8afad00a16 - Fixed tests 2009-12-04 11:32:39 +00:00
Dmitry Stogov 5ab649e65f Fixed compilation 2009-12-04 07:11:37 +00:00
Stanislav Malyshev 3e6ac4fb6b protect http_session_vars from interrupt corruption
improve save_path check
2009-12-04 01:21:32 +00:00
Jani Taskinen 1f8638b1f1 bfn 2009-12-03 22:24:04 +00:00
Rob Richards 3fa1ea9731 fix bug #47848 (importNode doesn't preserve attribute namespaces)
add tests
2009-12-03 20:19:38 +00:00
Pierrick Charron e2efe4bc7b Fixed bug #45120 (PDOStatement->execute() returns true then false for same statement). 2009-12-03 15:24:43 +00:00
Felipe Pena 7914d298b4 - Fixed bug #49472 (Constants defined in Interfaces can be overridden) 2009-12-03 12:34:50 +00:00
Kalle Sommer Nielsen 1063c8346b MFT: VC10 build support 2009-12-03 11:50:32 +00:00
Andrey Hristov 0f0f5f229b I svn-commit.2.tmp (Modified) Row 2 Col 28 11:45 Ctrl-K H for help
fix compilation on windows and with other compilers who
don't like void* arithmetic
2009-12-03 10:50:02 +00:00
Pierre Joye 2386938aea - disable this debug code until it is actually fixed 2009-12-03 10:41:20 +00:00
Andrey Hristov bfc0ec1891 fix segfault introduced by Pierre in a recent commit
old code was doing something like
conn + sizeof(MYSQLND) * MYSQLND + plugin * sizeof(void) * sizeof(MYSQLND)
because `conn` is not casted to void*. `conn` has to be casted to void * and
then the whole experession will be void * and the calculations will work.
2009-12-03 09:43:26 +00:00
Jani Taskinen 28d53f8752 the order 2009-12-03 08:21:28 +00:00
Ilia Alshanetsky 6f3532a266 BFN 2009-12-03 00:11:58 +00:00
Gwynne Raskind ea03ad31b7 One change in trying to update Autoconf was missed. This makes phpize work again. 2009-12-02 17:42:58 +00:00
160 changed files with 12002 additions and 11483 deletions

No files matched your search

+52 -3
View File
@@ -1,7 +1,7 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 20??, PHP 5.3.2
- Upgraded bundled sqlite to version 3.6.20. (Ilia)
22 Dec 2009, PHP 5.3.2 RC 1
- Upgraded bundled sqlite to version 3.6.21. (Ilia)
- Upgraded bundled PCRE to version 8.00. (Scott)
- Changed gmp_strval() to use full range from 2 to 62, and -2 to -36. FR #50283
@@ -9,6 +9,12 @@ PHP NEWS
- Changed "post_max_size" php.ini directive to allow unlimited post size by
setting it to 0. (Rasmus)
- Added INTERNALDATE support to imap_append. (nick at mailtrust dot com)
- Added support for SHA-256 and SHA-512 to php's crypt. (Pierre)
- Added realpath_cache_size() and realpath_cache_get() functions. (Stas)
- Added FILTER_FLAG_STRIP_BACKTICK option to the filter extension. (Ilia)
- Added protection for $_SESSION from interrupt corruption and improved
"session.save_path" check. (Stas)
- Added LIBXML_PARSEHUGE constant to override the maximum text size of a
single text node when using libxml2.7.3+. (Kalle)
- Added ReflectionMethod::setAccessible() for invoking non-public methods
@@ -19,6 +25,9 @@ PHP NEWS
(Linus Nielsen Feltzing <linus@haxx.se>)
- Added client-side server name indication support in openssl. (Arnaud)
- Improved fix for bug #50006 (Segfault caused by uksort()). (Stas)
- Fixed mysqlnd hang when queries exactly 16777214 bytes long are sent. (Andrey)
- Fixed incorrect decoding of 5-byte BIT sequences in mysqlnd. (Andrey)
- Fixed error_log() to be binary safe when using message_type 3. (Jani)
- Fixed unnecessary invocation of setitimer when timeouts have been disabled.
@@ -26,9 +35,28 @@ PHP NEWS
- Fixed memory leak in extension loading when an error occurs on Windows.
(Pierre)
- Fixed bug #50540 (Crash while running ldap_next_reference test cases).
(Sriram)
- Fixed bug #50508 (compile failure: Conflicting HEADER type declarations).
(Jani)
- Fixed bug #50496 (Use of <stdbool.h> is valid only in a c99 compilation
environment. (Sriram)
- Fixed bug #50464 (declare encoding doesn't work within an included file).
(Felipe)
- Fixed bug #50458 (PDO::FETCH_FUNC fails with Closures). (Felipe, Pierrick)
- Fixed bug #50445 (PDO-ODBC stored procedure call from Solaris 64-bit causes
seg fault). (davbrown4 at yahoo dot com, Felipe)
- Fixed bug #50394 (Reference argument converted to value in __call). (Stas)
- Fixed bug #50351 (performance regression handling objects, ten times slower
in 5.3 than in 5.2). (Dmitry)
- Fixed bug #50392 (date_create_from_format() enforces 6 digits for 'u'
format character). (Ilia)
- Fixed bug #50345 (nanosleep not detected properly on some solaris versions).
(Jani)
- Fixed bug #50340 (php.ini parser does not allow spaces in ini keys). (Jani)
- Fixed bug #50334 (crypt ignores sha512 prefix). (Pierre)
- Fixed bug #50323 (Allow use of ; in values via ;; in PDO DSN).
(Ilia, Pierrick)
- Fixed bug #50285 (xmlrpc does not preserve keys in encoded indexed arrays).
(Felipe)
- Fixed bug #50282 (xmlrpc_encode_request() changes object into array in
@@ -47,14 +75,20 @@ PHP NEWS
(Pierrick)
- Fixed bug #50212 (crash by ldap_get_option() with LDAP_OPT_NETWORK_TIMEOUT).
(Ilia, shigeru_kitazaki at cybozu dot co dot jp)
- Fixed bug #50209 (Compiling with libedit cannot find readline.h).
(tcallawa at redhat dot com)
- Fixed bug #50207 (segmentation fault when concatenating very large strings on
64bit linux). (Ilia)
- Fixed bug #50196 (stream_copy_to_stream() produces warning when source is
not file). (Stas)
- Fixed bug #50195 (pg_copy_to() fails when table name contains schema. (Ilia)
- Fixed bug #50185 (ldap_get_entries() return false instead of an empty array
when there is no error). (Jani)
- Fixed bug #50174 (Incorrectly matched docComment). (Felipe)
- Fixed bug #50168 (FastCGI fails with wrong error on HEAD request to
non-existant file). (Dmitry)
- Fixed bug #50162 (Memory leak when fetching timestamp column from Oracle
database). (Felipe)
- Fixed bug #50159 (wrong working directory in symlinked files). (Dmitry)
- Fixed bug #50158 (FILTER_VALIDATE_EMAIL fails with valid addresses
containing = or ?). (Pierrick)
@@ -78,8 +112,11 @@ PHP NEWS
- Fixed bug #49936 (crash with ftp stream in php_stream_context_get_option()).
(Pierrick)
- Fixed bug #49921 (Curl post upload functions changed). (Ilia)
- Fixed bug #49866 (Making reference on string offsets crashes PHP). (Dmitry)
- Fixed bug #49855 (import_request_variables() always returns NULL). (Ilia,
sjoerd at php dot net)
- Fixed bug #49851, #50451 (http wrapper breaks on 1024 char long headers).
(Ilia)
- Fixed bug #49800 (SimpleXML allow (un)serialize() calls without warning).
(Ilia, wmeler at wp-sa dot pl)
- Fixed bug #49719 (ReflectionClass::hasProperty returns true for a private
@@ -90,10 +127,22 @@ PHP NEWS
- Fixed bug #49647 (DOMUserData does not exist). (Rob)
- Fixed bug #49521 (PDO fetchObject sets values before calling constructor).
(Pierrick)
- Fixed bug #49472 (Constants defined in Interfaces can be overridden).
(Felipe)
- Fixed bug #49244 (Floating point NaN cause garbage characters). (Sjoerd)
- Fixed bug #49224 (Compile error due to old DNS functions on AIX systems).
(Scott)
- Fixed bug #49174 (crash when extending PDOStatement and trying to set
queryString property). (Felipe)
- Fixed bug #47848 (importNode doesn't preserve attribute namespaces). (Rob)
- Fixed bug #46478 (htmlentities() uses obsolete mapping table for character
entity references). (Moriyoshi)
- Fixed bug #45599 (strip_tags() truncates rest of string with invalid
attribute). (Ilia, hradtke)
- Fixed bug #45120 (PDOStatement->execute() returns true then false for same
statement). (Pierrick)
- Fixed bug #34852 (Failure in odbc_exec() using oracle-supplied odbc
driver). (tim dot tassonis at trivadis dot com)
19 Nov 2009, PHP 5.3.1
- Upgraded bundled sqlite to version 3.6.19. (Scott)
+16
View File
@@ -590,6 +590,22 @@ CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int path_
}
/* }}} */
CWD_API int realpath_cache_size(TSRMLS_D)
{
return CWDG(realpath_cache_size);
}
CWD_API int realpath_cache_max_buckets(TSRMLS_D)
{
return (sizeof(CWDG(realpath_cache)) / sizeof(CWDG(realpath_cache)[0]));
}
CWD_API realpath_cache_bucket** realpath_cache_get_buckets(TSRMLS_D)
{
return CWDG(realpath_cache);
}
#undef LINK_MAX
#define LINK_MAX 32
+3
View File
@@ -238,6 +238,9 @@ extern virtual_cwd_globals cwd_globals;
CWD_API void realpath_cache_clean(TSRMLS_D);
CWD_API void realpath_cache_del(const char *path, int path_len TSRMLS_DC);
CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int path_len, time_t t TSRMLS_DC);
CWD_API int realpath_cache_size(TSRMLS_D);
CWD_API int realpath_cache_max_buckets(TSRMLS_D);
CWD_API realpath_cache_bucket** realpath_cache_get_buckets(TSRMLS_D);
/* The actual macros to be used in programs using TSRM
* If the program defines VIRTUAL_DIR it will use the
+27
View File
@@ -0,0 +1,27 @@
--TEST--
Bug #49472 (Constants defined in Interfaces can be overridden)
--FILE--
<?php
interface ia {
const c = 'Sea';
const y = 2;
}
class Foo implements ia {
}
class FooBar extends Foo implements ia {
const x = 1;
const c = 'Ocean';
public function show() {
return ia::c;
}
}
new FooBar;
?>
--EXPECTF--
Fatal error: Cannot inherit previously-inherited or override constant c from interface ia in %s on line %d
+10
View File
@@ -0,0 +1,10 @@
--TEST--
Bug #49866 (Making reference on string offsets crashes PHP)
--FILE--
<?php
$a = "string";
$b = &$a[1];
$b = "f";
echo $a;
--EXPECTF--
Fatal error: Cannot create references to/from string offsets nor overloaded objects in %sbug49866.php on line 3
+24
View File
@@ -0,0 +1,24 @@
--TEST--
Bug #50394: Reference argument converted to value in __call
--FILE--
<?php
function inc( &$x ) { $x++; }
class Proxy {
function __call( $name, $args ) {
echo "$name called!\n";
call_user_func_array( 'inc', $args );
}
}
$arg = 1;
$args = array( &$arg );
$proxy = new Proxy;
call_user_func_array( array( $proxy, 'bar' ), $args );
call_user_func_array( array( $proxy, 'bar' ), array(&$arg) );
var_dump($arg);
--EXPECT--
bar called!
bar called!
int(3)
+18
View File
@@ -0,0 +1,18 @@
--TEST--
Calling non-static method with call_user_func()
--FILE--
<?php
class foo {
public function teste() {
$this->a = 1;
}
}
call_user_func(array('foo', 'teste'));
?>
--EXPECTF--
Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method foo::teste() should not be called statically in %s on line %d
Fatal error: Using $this when not in object context in %s on line %d
+35
View File
@@ -0,0 +1,35 @@
--TEST--
Passing Closure as parameter to an non-existent function
--FILE--
<?php
class foo {
public static function __callstatic($x, $y) {
var_dump($x,$y);
return 1;
}
public function teste() {
return foo::x(function &($a=1,$b) { });
}
}
var_dump(call_user_func(array('foo', 'teste')));
?>
--EXPECTF--
Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method foo::teste() should not be called statically in %s on line %d
%string|unicode%(1) "x"
array(1) {
[0]=>
object(Closure)#%d (1) {
["parameter"]=>
array(2) {
["$a"]=>
string(10) "<required>"
["$b"]=>
string(10) "<required>"
}
}
}
int(1)
+18
View File
@@ -0,0 +1,18 @@
--TEST--
Check call to non-ref function with call-time refs
--FILE--
<?php
function my_errorhandler($errno,$errormsg) {
global $my_var;
$my_var=0x12345;
echo $errormsg."\n";
return true;
}
$oldhandler = set_error_handler("my_errorhandler");
$my_var = str_repeat("A",64);
$data = call_user_func_array("substr_replace",array(&$my_var, new StdClass(),1));
echo "OK!";
--EXPECT--
Object of class stdClass could not be converted to string
Object of class stdClass to string conversion
OK!
+31
View File
@@ -0,0 +1,31 @@
--TEST--
Testing recursion detection with Closures
--FILE--
<?php
$x = function () use (&$x) {
$h = function () use ($x) {
var_dump($x);
return 1;
};
return $h();
};
var_dump($x());
?>
--EXPECTF--
object(Closure)#%d (1) {
["static"]=>
array(1) {
[%u|b%"x"]=>
&object(Closure)#%d (1) {
["static"]=>
array(1) {
[%u|b%"x"]=>
*RECURSION*
}
}
}
}
int(1)
+2 -2
View File
@@ -16,5 +16,5 @@ class test implements test1, test2 {
echo "Done\n";
?>
--EXPECTF--
Fatal error: Cannot inherit previously-inherited constant FOO from interface test2 in %s on line %d
--EXPECTF--
Fatal error: Cannot inherit previously-inherited or override constant FOO from interface test2 in %s on line %d
+1 -1
View File
@@ -15,4 +15,4 @@ class foobar implements foo {
}
?>
--EXPECTF--
Fatal error: Cannot inherit previously-inherited constant foo from interface foo in %s on line %d
Fatal error: Cannot inherit previously-inherited or override constant foo from interface foo in %s on line %d
+5
View File
@@ -710,6 +710,11 @@ END_EXTERN_C()
FREE_ZVAL(pzv); \
} \
INIT_PZVAL(&(zv));
#define MAKE_COPY_ZVAL(ppzv, pzv) \
*(pzv) = **(ppzv); \
zval_copy_ctor((pzv)); \
INIT_PZVAL((pzv));
#define REPLACE_ZVAL_VALUE(ppzv_dest, pzv_src, copy) { \
int is_ref, refcount; \
+17 -4
View File
@@ -2876,8 +2876,8 @@ static zend_bool do_inherit_constant_check(HashTable *child_constants_table, con
zval **old_constant;
if (zend_hash_quick_find(child_constants_table, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void**)&old_constant) == SUCCESS) {
if (*old_constant != *parent_constant) {
zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited constant %s from interface %s", hash_key->arKey, iface->name);
if (*old_constant != *parent_constant) {
zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited or override constant %s from interface %s", hash_key->arKey, iface->name);
}
return 0;
}
@@ -2885,6 +2885,16 @@ static zend_bool do_inherit_constant_check(HashTable *child_constants_table, con
}
/* }}} */
static int do_interface_constant_check(zval **val TSRMLS_DC, int num_args, va_list args, const zend_hash_key *key) /* {{{ */
{
zend_class_entry **iface = va_arg(args, zend_class_entry**);
do_inherit_constant_check(&(*iface)->constants_table, (const zval **) val, key, *iface);
return ZEND_HASH_APPLY_KEEP;
}
/* }}} */
ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC) /* {{{ */
{
zend_uint i, ignore = 0;
@@ -2903,7 +2913,10 @@ ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry
}
}
}
if (!ignore) {
if (ignore) {
/* Check for attempt to redeclare interface constants */
zend_hash_apply_with_arguments(&ce->constants_table TSRMLS_CC, (apply_func_args_t) do_interface_constant_check, 1, &iface);
} else {
if (ce->num_interfaces >= current_iface_num) {
if (ce->type == ZEND_INTERNAL_CLASS) {
ce->interfaces = (zend_class_entry **) realloc(ce->interfaces, sizeof(zend_class_entry *) * (++current_iface_num));
@@ -4651,7 +4664,7 @@ void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC) /* {{{ */
--num;
}
if (num > 0 || CG(encoding_declared)) {
if (num > 0) {
zend_error(E_COMPILE_ERROR, "Encoding declaration pragma must be the very first statement in the script");
}
}
+1
View File
@@ -838,6 +838,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
zval *param;
if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION
&& (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) == 0
&& !ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)
&& PZVAL_IS_REF(*fci->params[i])) {
SEPARATE_ZVAL(fci->params[i]);
+1 -1
View File
@@ -1,4 +1,4 @@
/* Generated by re2c 0.13.5 on Tue Dec 1 00:06:21 2009 */
/* Generated by re2c 0.13.5 on Tue Dec 8 12:24:52 2009 */
#line 1 "Zend/zend_ini_scanner.l"
/*
+----------------------------------------------------------------------+
+1 -1
View File
@@ -1,4 +1,4 @@
/* Generated by re2c 0.13.5 on Tue Dec 1 00:06:21 2009 */
/* Generated by re2c 0.13.5 on Tue Dec 8 12:24:52 2009 */
#line 3 "Zend/zend_ini_scanner_defs.h"
enum YYCONDTYPE {
+2 -4
View File
@@ -1100,7 +1100,7 @@ ZEND_VM_HANDLER(84, ZEND_FETCH_DIM_W, VAR|CV, CONST|TMP|VAR|UNUSED|CV)
FREE_OP1_VAR_PTR();
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -3691,7 +3691,7 @@ ZEND_VM_HANDLER(78, ZEND_FE_FETCH, VAR, ANY)
{
zend_op *opline = EX(opline);
zend_free_op free_op1;
zval *array = GET_OP1_ZVAL_PTR(BP_VAR_R);
zval *array = EX_T(opline->op1.u.var).var.ptr;
zval **value;
char *str_key;
uint str_key_len;
@@ -3701,8 +3701,6 @@ ZEND_VM_HANDLER(78, ZEND_FE_FETCH, VAR, ANY)
int key_type = 0;
zend_bool use_key = (zend_bool)(opline->extended_value & ZEND_FE_FETCH_WITH_KEY);
PZVAL_LOCK(array);
switch (zend_iterator_unwrap(array, &iter TSRMLS_CC)) {
default:
case ZEND_ITER_INVALID:
+12 -14
View File
@@ -8851,8 +8851,8 @@ static int ZEND_FASTCALL ZEND_FE_RESET_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG
static int ZEND_FASTCALL ZEND_FE_FETCH_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
zend_op *opline = EX(opline);
zend_free_op free_op1;
zval *array = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
zval *array = EX_T(opline->op1.u.var).var.ptr;
zval **value;
char *str_key;
uint str_key_len;
@@ -8862,8 +8862,6 @@ static int ZEND_FASTCALL ZEND_FE_FETCH_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG
int key_type = 0;
zend_bool use_key = (zend_bool)(opline->extended_value & ZEND_FE_FETCH_WITH_KEY);
PZVAL_LOCK(array);
switch (zend_iterator_unwrap(array, &iter TSRMLS_CC)) {
default:
case ZEND_ITER_INVALID:
@@ -9866,7 +9864,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE_HA
if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -11669,7 +11667,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_VAR_TMP_HANDLER(ZEND_OPCODE_HAND
if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -13418,7 +13416,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_VAR_VAR_HANDLER(ZEND_OPCODE_HAND
if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -14758,7 +14756,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_VAR_UNUSED_HANDLER(ZEND_OPCODE_H
if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -15809,7 +15807,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDL
if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -23569,7 +23567,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_CV_CONST_HANDLER(ZEND_OPCODE_HAN
}
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -25206,7 +25204,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_CV_TMP_HANDLER(ZEND_OPCODE_HANDL
}
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -26846,7 +26844,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_CV_VAR_HANDLER(ZEND_OPCODE_HANDL
}
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -28076,7 +28074,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_CV_UNUSED_HANDLER(ZEND_OPCODE_HA
}
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
@@ -29028,7 +29026,7 @@ static int ZEND_FASTCALL ZEND_FETCH_DIM_W_SPEC_CV_CV_HANDLER(ZEND_OPCODE_HANDLE
}
/* We are going to assign the result by reference */
if (opline->extended_value) {
if (opline->extended_value && EX_T(opline->result.u.var).var.ptr_ptr) {
Z_DELREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
SEPARATE_ZVAL_TO_MAKE_IS_REF(EX_T(opline->result.u.var).var.ptr_ptr);
Z_ADDREF_PP(EX_T(opline->result.u.var).var.ptr_ptr);
+10 -4
View File
@@ -42,7 +42,7 @@ AC_CONFIG_HEADER(main/php_config.h)
PHP_MAJOR_VERSION=5
PHP_MINOR_VERSION=3
PHP_RELEASE_VERSION=2
PHP_EXTRA_VERSION="-dev"
PHP_EXTRA_VERSION="RC1"
PHP_VERSION="$PHP_MAJOR_VERSION.$PHP_MINOR_VERSION.$PHP_RELEASE_VERSION$PHP_EXTRA_VERSION"
PHP_VERSION_ID=`expr [$]PHP_MAJOR_VERSION \* 10000 + [$]PHP_MINOR_VERSION \* 100 + [$]PHP_RELEASE_VERSION`
@@ -202,7 +202,12 @@ case $host_cpu in
;;
sparc*)
if test "$SUNCC" = "yes"; then
CFLAGS="$CFLAGS -xmemalign=8s"
CFLAGS="$CFLAGS -xc99=all -xmemalign=8s"
fi
;;
i386)
if test "$SUNCC" = "yes"; then
CFLAGS="$CFLAGS -xc99=all"
fi
;;
esac
@@ -406,7 +411,6 @@ sys/time.h \
netinet/in.h \
alloca.h \
arpa/inet.h \
arpa/nameser_compat.h \
arpa/nameser.h \
assert.h \
crypt.h \
@@ -980,7 +984,6 @@ case $php_build_target in
esac
EXTRA_LIBS="$EXTRA_LIBS $DLIBS $LIBS"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LDFLAGS"
dnl this has to be here to prevent the openssl crypt() from
dnl overriding the system provided crypt().
@@ -1157,6 +1160,7 @@ EXPANDED_PEAR_INSTALLDIR=`eval echo $PEAR_INSTALLDIR`
EXPANDED_EXTENSION_DIR=`eval echo $EXTENSION_DIR`
EXPANDED_LOCALSTATEDIR=`eval echo $localstatedir`
EXPANDED_BINDIR=`eval echo $bindir`
EXPANDED_SBINDIR=`eval echo $sbindir`
EXPANDED_LIBDIR=$libdir
EXPANDED_SYSCONFDIR=`eval echo $sysconfdir`
EXPANDED_DATADIR=$datadir
@@ -1172,6 +1176,7 @@ AC_SUBST(INCLUDE_PATH)
AC_SUBST(EXPANDED_PEAR_INSTALLDIR)
AC_SUBST(EXPANDED_EXTENSION_DIR)
AC_SUBST(EXPANDED_BINDIR)
AC_SUBST(EXPANDED_SBINDIR)
AC_SUBST(EXPANDED_LIBDIR)
AC_SUBST(EXPANDED_DATADIR)
AC_SUBST(EXPANDED_SYSCONFDIR)
@@ -1240,6 +1245,7 @@ PHP_SUBST_OLD(php_abs_top_builddir)
PHP_SUBST_OLD(php_abs_top_srcdir)
PHP_SUBST(bindir)
PHP_SUBST(sbindir)
PHP_SUBST(exec_prefix)
PHP_SUBST_OLD(program_prefix)
PHP_SUBST_OLD(program_suffix)
+4 -4
View File
@@ -1,4 +1,4 @@
/* Generated by re2c 0.13.5 on Wed Jul 29 16:20:12 2009 */
/* Generated by re2c 0.13.5 on Mon Dec 14 07:41:45 2009 */
#line 1 "ext/date/lib/parse_date.re"
/*
+----------------------------------------------------------------------+
@@ -24086,15 +24086,15 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
add_pbf_error(s, "A two digit second could not be found", string, begin);
}
break;
case 'u': /* six digit millisecond */
case 'u': /* up to six digit millisecond */
{
double f;
char *tptr;
TIMELIB_CHECK_NUMBER;
tptr = ptr;
if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || ptr - tptr != 6) {
add_pbf_error(s, "A six digit millisecond could not be found", string, begin);
if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || (ptr - tptr) < 1) {
add_pbf_error(s, "At least a single digit millisecond could not be found", string, begin);
} else {
s->time->f = (f / 1000000);
}
+3 -3
View File
@@ -1943,15 +1943,15 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
add_pbf_error(s, "A two digit second could not be found", string, begin);
}
break;
case 'u': /* six digit millisecond */
case 'u': /* up to six digit millisecond */
{
double f;
char *tptr;
TIMELIB_CHECK_NUMBER;
tptr = ptr;
if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || ptr - tptr != 6) {
add_pbf_error(s, "A six digit millisecond could not be found", string, begin);
if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || (ptr - tptr) < 1) {
add_pbf_error(s, "At least a single digit millisecond could not be found", string, begin);
} else {
s->time->f = (f / 1000000);
}
+1 -1
View File
@@ -18062,4 +18062,4 @@ const unsigned char timelib_timezone_db_data_builtin[257094] = {
0x00, 0x00, 0x55, 0x54, 0x43, 0x00, 0x00, 0x00, 0x00, 0x89, 0x54, 0x40, 0x01, 0x12, 0xA8, 0x80,
0x00, 0x00, 0x00, 0x00, };
const timelib_tzdb timezonedb_builtin = { "2009.19", 561, timezonedb_idx_builtin, timelib_timezone_db_data_builtin };
const timelib_tzdb timezonedb_builtin = { "2009.20", 561, timezonedb_idx_builtin, timelib_timezone_db_data_builtin };
+63
View File
@@ -0,0 +1,63 @@
--TEST--
Bug #50392 date_create_from_format enforces 6 digits for 'u' format character
--FILE--
<?php
date_default_timezone_set('Europe/Bratislava');
$base = '2009-03-01 18:00:00';
for ($i = 0; $i < 8; $i++) {
var_dump(date_create_from_format('Y-m-d H:i:s.u', $base . '.' . str_repeat('1', $i)));
}
?>
--EXPECT--
bool(false)
object(DateTime)#2 (3) {
["date"]=>
string(19) "2009-03-01 18:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(17) "Europe/Bratislava"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2009-03-01 18:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(17) "Europe/Bratislava"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2009-03-01 18:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(17) "Europe/Bratislava"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2009-03-01 18:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(17) "Europe/Bratislava"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2009-03-01 18:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(17) "Europe/Bratislava"
}
object(DateTime)#2 (3) {
["date"]=>
string(19) "2009-03-01 18:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(17) "Europe/Bratislava"
}
bool(false)
+12 -1
View File
@@ -1203,7 +1203,18 @@ PHP_FUNCTION(dom_document_import_node)
if (!retnodep) {
RETURN_FALSE;
}
if ((retnodep->type == XML_ATTRIBUTE_NODE) && (nodep->ns != NULL)) {
xmlNsPtr nsptr = NULL;
xmlNodePtr root = xmlDocGetRootElement(docp);
nsptr = xmlSearchNsByHref (nodep->doc, root, nodep->ns->href);
if (nsptr == NULL) {
int errorcode;
nsptr = dom_get_ns(root, nodep->ns->href, &errorcode, nodep->ns->prefix);
}
xmlSetNs(retnodep, nsptr);
}
}
DOM_RET_OBJ(rv, (xmlNodePtr) retnodep, &ret, intern);
+25
View File
@@ -0,0 +1,25 @@
--TEST--
Bug #47848 (importNode doesn't preserve attribute namespaces)
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
$aDOM = new DOMDocument();
$aDOM->appendChild($aDOM->createElementNS('http://friend2friend.net/','f2f:a'));
$fromdom = new DOMDocument();
$fromdom->loadXML('<data xmlns:ai="http://altruists.org" ai:attr="namespaced" />');
$attr= $fromdom->firstChild->attributes->item(0);
$att = $aDOM->importNode($attr);
$aDOM->documentElement->appendChild($aDOM->importNode($attr, true));
echo $aDOM->saveXML();
?>
--EXPECT--
<?xml version="1.0"?>
<f2f:a xmlns:f2f="http://friend2friend.net/" xmlns:ai="http://altruists.org" ai:attr="namespaced"/>
+9 -24
View File
@@ -251,6 +251,7 @@ PHP_MINIT_FUNCTION(filter)
REGISTER_LONG_CONSTANT("FILTER_FLAG_STRIP_LOW", FILTER_FLAG_STRIP_LOW, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("FILTER_FLAG_STRIP_HIGH", FILTER_FLAG_STRIP_HIGH, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("FILTER_FLAG_STRIP_BACKTICK", FILTER_FLAG_STRIP_BACKTICK, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("FILTER_FLAG_ENCODE_LOW", FILTER_FLAG_ENCODE_LOW, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("FILTER_FLAG_ENCODE_HIGH", FILTER_FLAG_ENCODE_HIGH, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("FILTER_FLAG_ENCODE_AMP", FILTER_FLAG_ENCODE_AMP, CONST_CS | CONST_PERSISTENT);
@@ -391,9 +392,7 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
) {
zval **tmp;
if (zend_hash_find(HASH_OF(options), "default", sizeof("default"), (void **)&tmp) == SUCCESS) {
**value = **tmp;
zval_copy_ctor(*value);
INIT_PZVAL(*value);
MAKE_COPY_ZVAL(tmp, *value);
}
}
}
@@ -678,9 +677,7 @@ static void php_filter_call(zval **filtered, long filter, zval **filter_args, co
zval *tmp;
ALLOC_ZVAL(tmp);
*tmp = **filtered;
zval_copy_ctor(tmp);
INIT_PZVAL(tmp);
MAKE_COPY_ZVAL(filtered, tmp);
zval_dtor(*filtered);
@@ -700,15 +697,11 @@ static void php_filter_array_handler(zval *input, zval **op, zval *return_value
if (!op) {
zval_dtor(return_value);
*return_value = *input;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(&input, return_value);
php_filter_call(&return_value, FILTER_DEFAULT, NULL, 0, FILTER_REQUIRE_ARRAY TSRMLS_CC);
} else if (Z_TYPE_PP(op) == IS_LONG) {
zval_dtor(return_value);
*return_value = *input;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(&input, return_value);
php_filter_call(&return_value, Z_LVAL_PP(op), NULL, 0, FILTER_REQUIRE_ARRAY TSRMLS_CC);
} else if (Z_TYPE_PP(op) == IS_ARRAY) {
array_init(return_value);
@@ -734,9 +727,7 @@ static void php_filter_array_handler(zval *input, zval **op, zval *return_value
zval *nval;
ALLOC_ZVAL(nval);
*nval = **tmp;
zval_copy_ctor(nval);
INIT_PZVAL(nval);
MAKE_COPY_ZVAL(tmp, nval);
php_filter_call(&nval, -1, arg_elm, 0, FILTER_REQUIRE_SCALAR TSRMLS_CC);
add_assoc_zval_ex(return_value, arg_key, arg_key_len, nval);
@@ -782,9 +773,7 @@ PHP_FUNCTION(filter_input)
Z_TYPE_PP(opt) == IS_ARRAY &&
zend_hash_find(HASH_OF(*opt), "default", sizeof("default"), (void **)&def) == SUCCESS
) {
*return_value = **def;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(def, return_value);
return;
}
}
@@ -795,9 +784,7 @@ PHP_FUNCTION(filter_input)
}
}
*return_value = **tmp;
zval_copy_ctor(return_value); /* Watch out for empty strings */
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(tmp, return_value);
php_filter_call(&return_value, filter, filter_args, 1, FILTER_REQUIRE_SCALAR TSRMLS_CC);
}
@@ -819,9 +806,7 @@ PHP_FUNCTION(filter_var)
RETURN_FALSE;
}
*return_value = *data;
zval_copy_ctor(data);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(&data, return_value);
php_filter_call(&return_value, filter, filter_args, 1, FILTER_REQUIRE_SCALAR TSRMLS_CC);
}
+1
View File
@@ -39,6 +39,7 @@
#define FILTER_FLAG_ENCODE_AMP 0x0040
#define FILTER_FLAG_NO_ENCODE_QUOTES 0x0080
#define FILTER_FLAG_EMPTY_STRING_NULL 0x0100
#define FILTER_FLAG_STRIP_BACKTICK 0x0200
#define FILTER_FLAG_ALLOW_FRACTION 0x1000
#define FILTER_FLAG_ALLOW_THOUSAND 0x2000
+1
View File
@@ -123,6 +123,7 @@ static void php_filter_strip(zval *value, long flags)
for (i = 0; i < Z_STRLEN_P(value); i++) {
if ((str[i] > 127) && (flags & FILTER_FLAG_STRIP_HIGH)) {
} else if ((str[i] < 32) && (flags & FILTER_FLAG_STRIP_LOW)) {
} else if ((str[i] == '`') && (flags & FILTER_FLAG_STRIP_BACKTICK)) {
} else {
buf[c] = str[i];
++c;
+1
View File
@@ -3,6 +3,7 @@ Bug #42718 - 2 (unsafe_raw filter not applied when configured as default filter)
--SKIPIF--
<?php if (!extension_loaded("filter")) die("skip"); ?>
--INI--
display_errors=0
magic_quotes_gpc=1
filter.default=unsafe_raw
filter.default_flags=
+1 -1
View File
@@ -4139,7 +4139,7 @@ PHP_FUNCTION(imagepsencodefont)
T1_DeleteAllSizes(*f_ind);
if (T1_ReencodeFont(*f_ind, enc_vector)) {
T1_DeleteEncoding(enc_vector);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't reencode font");
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't re-encode font");
RETURN_FALSE;
}
+1
View File
@@ -8,6 +8,7 @@ if (PHP_GMP != "no") {
CHECK_HEADER_ADD_INCLUDE("gmp.h", "CFLAGS_GMP", PHP_GMP + ";" + PHP_PHP_BUILD + "\\include\\mpir")) {
EXTENSION("gmp", "gmp.c");
AC_DEFINE('HAVE_GMP', 1, 'GMP support');
AC_DEFINE('HAVE_MPIR', 1, 'MPIR support');
} else {
WARNING("GMP not enabled; libraries and headers not found");
}
+8 -1
View File
@@ -356,6 +356,9 @@ ZEND_MODULE_STARTUP_D(gmp)
REGISTER_LONG_CONSTANT("GMP_ROUND_ZERO", GMP_ROUND_ZERO, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_ROUND_PLUSINF", GMP_ROUND_PLUSINF, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GMP_ROUND_MINUSINF", GMP_ROUND_MINUSINF, CONST_CS | CONST_PERSISTENT);
#ifdef mpir_version
REGISTER_STRING_CONSTANT("GMP_MPIR_VERSION", (char *)mpir_version, CONST_CS | CONST_PERSISTENT);
#endif
REGISTER_STRING_CONSTANT("GMP_VERSION", (char *)gmp_version, CONST_CS | CONST_PERSISTENT);
mp_set_memory_functions(gmp_emalloc, gmp_erealloc, gmp_efree);
@@ -383,7 +386,11 @@ ZEND_MODULE_INFO_D(gmp)
{
php_info_print_table_start();
php_info_print_table_row(2, "gmp support", "enabled");
#ifdef mpir_version
php_info_print_table_row(2, "MPIR version", mpir_version);
#else
php_info_print_table_row(2, "GMP version", gmp_version);
#endif
php_info_print_table_end();
}
/* }}} */
@@ -746,7 +753,7 @@ ZEND_FUNCTION(gmp_init)
return;
}
#if __GNU_MP_VERSION >= 4 && __GNU_MP_VERSION_MINOR >= 2
#if (__GNU_MP_VERSION >= 4 && __GNU_MP_VERSION_MINOR >= 2)
if (base && (base < 2 || base > 62)) {
#else
if (base && (base < 2 || base > 36)) {
+29 -5
View File
@@ -41,6 +41,7 @@
#include "ext/standard/info.h"
#include "ext/standard/file.h"
#include "ext/standard/php_smart_str.h"
#include "ext/pcre/php_pcre.h"
#ifdef ERROR
#undef ERROR
@@ -118,6 +119,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_append, 0, 0, 3)
ZEND_ARG_INFO(0, folder)
ZEND_ARG_INFO(0, message)
ZEND_ARG_INFO(0, options)
ZEND_ARG_INFO(0, date)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_num_msg, 0, 0, 1)
@@ -1265,25 +1267,47 @@ PHP_FUNCTION(imap_reopen)
}
/* }}} */
/* {{{ proto bool imap_append(resource stream_id, string folder, string message [, string options])
/* {{{ proto bool imap_append(resource stream_id, string folder, string message [, string options [, string internal_date]])
Append a new message to a specified mailbox */
PHP_FUNCTION(imap_append)
{
zval *streamind;
char *folder, *message, *flags = NULL;
int folder_len, message_len, flags_len = 0;
char *folder, *message, *internal_date = NULL, *flags = NULL;
int folder_len, message_len, internal_date_len = 0, flags_len = 0;
pils *imap_le_struct;
STRING st;
char* regex = "/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/";
const int regex_len = strlen(regex);
pcre_cache_entry *pce; /* Compiled regex */
zval *subpats = NULL; /* Parts (not used) */
long regex_flags = 0; /* Flags (not used) */
long start_offset = 0; /* Start offset (not used) */
int global = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|s", &streamind, &folder, &folder_len, &message, &message_len, &flags, &flags_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|ss", &streamind, &folder, &folder_len, &message, &message_len, &flags, &flags_len, &internal_date, &internal_date_len) == FAILURE) {
return;
}
if (internal_date) {
/* Make sure the given internal_date string matches the RFC specifiedformat */
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC))== NULL) {
RETURN_FALSE;
}
php_pcre_match_impl(pce, internal_date, internal_date_len, return_value, subpats, global,
0, regex_flags, start_offset TSRMLS_CC);
if (!Z_LVAL_P(return_value)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "internal date not correctly formatted");
internal_date = NULL;
}
}
ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
INIT (&st, mail_string, (void *) message, message_len);
if (mail_append_full(imap_le_struct->imap_stream, folder, (flags ? flags : NIL), NIL, &st)) {
if (mail_append_full(imap_le_struct->imap_stream, folder, (flags ? flags : NIL), (internal_date ? internal_date : NIL), &st)) {
RETURN_TRUE;
} else {
RETURN_FALSE;
-9
View File
@@ -39,14 +39,5 @@ typedef struct {
#define NORMALIZER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(NORMALIZER_ERROR(co)))
void normalizer_register_Normalizer_class( TSRMLS_D );
void normalizer_object_init( Normalizer_object* co TSRMLS_DC );
void normalizer_object_destroy( Normalizer_object* co TSRMLS_DC );
extern zend_class_entry *Normalizer_ce_ptr;
/* Auxiliary macros */
#define NORMALIZER_METHOD_INIT_VARS \
intl_error_reset( NULL TSRMLS_CC ); \
#endif // #ifndef NORMALIZER_CLASS_H
@@ -50,8 +50,6 @@ PHP_FUNCTION( normalizer_normalize )
int32_t size_needed;
NORMALIZER_METHOD_INIT_VARS
intl_error_reset( NULL TSRMLS_CC );
/* Parse parameters. */
@@ -181,8 +179,6 @@ PHP_FUNCTION( normalizer_is_normalized )
UBool uret = FALSE;
NORMALIZER_METHOD_INIT_VARS
intl_error_reset( NULL TSRMLS_CC );
/* Parse parameters. */
+2
View File
@@ -1911,6 +1911,7 @@ PHP_FUNCTION(ldap_first_reference)
resultentry->id = Z_LVAL_P(result);
zend_list_addref(resultentry->id);
resultentry->data = entry;
resultentry->ber = NULL;
}
}
/* }}} */
@@ -1939,6 +1940,7 @@ PHP_FUNCTION(ldap_next_reference)
resultentry_next->id = resultentry->id;
zend_list_addref(resultentry->id);
resultentry_next->data = entry_next;
resultentry_next->ber = NULL;
}
}
/* }}} */
+4 -43
View File
@@ -125,10 +125,6 @@ typedef struct _php_mysql_conn {
int multi_query;
} php_mysql_conn;
#ifdef MYSQL_USE_MYSQLND
static MYSQLND_ZVAL_PCACHE *mysql_mysqlnd_zval_cache;
static MYSQLND_QCACHE *mysql_mysqlnd_qcache;
#endif
#if MYSQL_VERSION_ID >= 40101
#define MYSQL_DISABLE_MQ if (mysql->multi_query) { \
@@ -411,9 +407,6 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("mysql.connect_timeout", "60", PHP_INI_ALL, OnUpdateLong, connect_timeout, zend_mysql_globals, mysql_globals)
STD_PHP_INI_BOOLEAN("mysql.trace_mode", "0", PHP_INI_ALL, OnUpdateLong, trace_mode, zend_mysql_globals, mysql_globals)
STD_PHP_INI_BOOLEAN("mysql.allow_local_infile", "1", PHP_INI_SYSTEM, OnUpdateLong, allow_local_infile, zend_mysql_globals, mysql_globals)
#ifdef MYSQL_USE_MYSQLND
STD_PHP_INI_ENTRY("mysql.cache_size", "2000", PHP_INI_SYSTEM, OnUpdateLong, cache_size, zend_mysql_globals, mysql_globals)
#endif
PHP_INI_END()
/* }}} */
@@ -432,10 +425,6 @@ static PHP_GINIT_FUNCTION(mysql)
mysql_globals->trace_mode = 0;
mysql_globals->allow_local_infile = 1;
mysql_globals->result_allocated = 0;
#ifdef MYSQL_USE_MYSQLND
mysql_globals->cache_size = 0;
mysql_globals->mysqlnd_thd_zval_cache = NULL;
#endif
}
/* }}} */
@@ -465,9 +454,6 @@ ZEND_MODULE_STARTUP_D(mysql)
return FAILURE;
}
#endif
#else
mysql_mysqlnd_zval_cache = mysqlnd_palloc_init_cache(MySG(cache_size));
mysql_mysqlnd_qcache = mysqlnd_qcache_init_cache();
#endif
return SUCCESS;
@@ -493,9 +479,6 @@ PHP_MSHUTDOWN_FUNCTION(mysql)
mysql_server_end();
#endif
#endif
#else
mysqlnd_palloc_free_cache(mysql_mysqlnd_zval_cache);
mysqlnd_qcache_free_cache_reference(&mysql_mysqlnd_qcache);
#endif
UNREGISTER_INI_ENTRIES();
@@ -519,10 +502,6 @@ PHP_RINIT_FUNCTION(mysql)
MySG(connect_errno) =0;
MySG(result_allocated) = 0;
#ifdef MYSQL_USE_MYSQLND
MySG(mysqlnd_thd_zval_cache) = mysqlnd_palloc_rinit(mysql_mysqlnd_zval_cache);
#endif
return SUCCESS;
}
/* }}} */
@@ -559,7 +538,6 @@ PHP_RSHUTDOWN_FUNCTION(mysql)
#ifdef MYSQL_USE_MYSQLND
zend_hash_apply(&EG(persistent_list), (apply_func_t) php_mysql_persistent_helper TSRMLS_CC);
mysqlnd_palloc_rshutdown(MySG(mysqlnd_thd_zval_cache));
#endif
return SUCCESS;
@@ -585,20 +563,6 @@ PHP_MINFO_FUNCTION(mysql)
php_info_print_table_row(2, "MYSQL_INCLUDE", PHP_MYSQL_INCLUDE);
php_info_print_table_row(2, "MYSQL_LIBS", PHP_MYSQL_LIBS);
#endif
#if defined(MYSQL_USE_MYSQLND)
{
zval values;
php_info_print_table_header(2, "Persistent cache", mysql_mysqlnd_zval_cache? "enabled":"disabled");
if (mysql_mysqlnd_zval_cache) {
/* Now report cache status */
mysqlnd_palloc_stats(mysql_mysqlnd_zval_cache, &values);
mysqlnd_minfo_print_hash(&values);
zval_dtor(&values);
}
}
#endif
php_info_print_table_end();
@@ -776,8 +740,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifndef MYSQL_USE_MYSQLND
if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
#else
if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0,
port, socket, client_flags, MySG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0, port, socket, client_flags TSRMLS_CC) == NULL)
#endif
{
/* Populate connect error globals so that the error functions can read them */
@@ -825,8 +788,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifndef MYSQL_USE_MYSQLND
if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
#else
if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0,
port, socket, client_flags, MySG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0, port, socket, client_flags TSRMLS_CC) == NULL)
#endif
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Link to server lost, unable to reconnect");
@@ -838,7 +800,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
}
} else {
#ifdef MYSQL_USE_MYSQLND
mysqlnd_restart_psession(mysql->conn, MySG(mysqlnd_thd_zval_cache));
mysqlnd_restart_psession(mysql->conn);
#endif
}
}
@@ -897,8 +859,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifndef MYSQL_USE_MYSQLND
if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
#else
if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0,
port, socket, client_flags, MySG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0, port, socket, client_flags TSRMLS_CC) == NULL)
#endif
{
/* Populate connect error globals so that the error functions can read them */
-5
View File
@@ -124,11 +124,6 @@ ZEND_BEGIN_MODULE_GLOBALS(mysql)
long result_allocated;
long trace_mode;
long allow_local_infile;
#ifdef MYSQL_USE_MYSQLND
MYSQLND_THD_ZVAL_PCACHE *mysqlnd_thd_zval_cache;
MYSQLND_QCACHE *mysqlnd_qcache;
long cache_size;
#endif
ZEND_END_MODULE_GLOBALS(mysql)
#ifdef ZTS
-43
View File
@@ -73,11 +73,6 @@ zend_class_entry *mysqli_driver_class_entry;
zend_class_entry *mysqli_warning_class_entry;
zend_class_entry *mysqli_exception_class_entry;
#ifdef MYSQLI_USE_MYSQLND
MYSQLND_ZVAL_PCACHE *mysqli_mysqlnd_zval_cache;
MYSQLND_QCACHE *mysqli_mysqlnd_qcache;
#endif
typedef int (*mysqli_read_t)(mysqli_object *obj, zval **retval TSRMLS_DC);
typedef int (*mysqli_write_t)(mysqli_object *obj, zval *newval TSRMLS_DC);
@@ -589,9 +584,6 @@ PHP_INI_BEGIN()
#endif
STD_PHP_INI_BOOLEAN("mysqli.reconnect", "0", PHP_INI_SYSTEM, OnUpdateLong, reconnect, zend_mysqli_globals, mysqli_globals)
STD_PHP_INI_BOOLEAN("mysqli.allow_local_infile", "1", PHP_INI_SYSTEM, OnUpdateLong, allow_local_infile, zend_mysqli_globals, mysqli_globals)
#ifdef MYSQLI_USE_MYSQLND
STD_PHP_INI_ENTRY("mysqli.cache_size", "2000", PHP_INI_SYSTEM, OnUpdateLong, cache_size, zend_mysqli_globals, mysqli_globals)
#endif
PHP_INI_END()
/* }}} */
@@ -620,10 +612,6 @@ static PHP_GINIT_FUNCTION(mysqli)
#else
mysqli_globals->embedded = 0;
#endif
#ifdef MYSQLI_USE_MYSQLND
mysqli_globals->cache_size = 0;
mysqli_globals->mysqlnd_thd_zval_cache = NULL;
#endif
}
/* }}} */
@@ -641,9 +629,6 @@ PHP_MINIT_FUNCTION(mysqli)
return FAILURE;
}
#endif
#else
mysqli_mysqlnd_zval_cache = mysqlnd_palloc_init_cache(MyG(cache_size));
mysqli_mysqlnd_qcache = mysqlnd_qcache_init_cache();
#endif
memcpy(&mysqli_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
@@ -734,9 +719,6 @@ PHP_MINIT_FUNCTION(mysqli)
/* for mysqli_query */
REGISTER_LONG_CONSTANT("MYSQLI_STORE_RESULT", MYSQLI_STORE_RESULT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("MYSQLI_USE_RESULT", MYSQLI_USE_RESULT, CONST_CS | CONST_PERSISTENT);
#if defined(MYSQLI_USE_MYSQLND) && defined(MYSQLND_THREADED)
REGISTER_LONG_CONSTANT("MYSQLI_BG_STORE_RESULT", MYSQLI_BG_STORE_RESULT, CONST_CS | CONST_PERSISTENT);
#endif
#if defined (MYSQLI_USE_MYSQLND)
REGISTER_LONG_CONSTANT("MYSQLI_ASYNC", MYSQLI_ASYNC, CONST_CS | CONST_PERSISTENT);
#endif
@@ -884,9 +866,6 @@ PHP_MSHUTDOWN_FUNCTION(mysqli)
mysql_server_end();
#endif
#endif
#else
mysqlnd_palloc_free_cache(mysqli_mysqlnd_zval_cache);
mysqlnd_qcache_free_cache_reference(&mysqli_mysqlnd_qcache);
#endif
zend_hash_destroy(&mysqli_driver_properties);
@@ -912,9 +891,6 @@ PHP_RINIT_FUNCTION(mysqli)
#endif
MyG(error_msg) = NULL;
MyG(error_no) = 0;
#ifdef MYSQLI_USE_MYSQLND
MyG(mysqlnd_thd_zval_cache) = mysqlnd_palloc_rinit(mysqli_mysqlnd_zval_cache);
#endif
return SUCCESS;
}
@@ -954,7 +930,6 @@ PHP_RSHUTDOWN_FUNCTION(mysqli)
}
#ifdef MYSQLI_USE_MYSQLND
zend_hash_apply(&EG(persistent_list), (apply_func_t) php_mysqli_persistent_helper_once TSRMLS_CC);
mysqlnd_palloc_rshutdown(MyG(mysqlnd_thd_zval_cache));
#endif
return SUCCESS;
}
@@ -979,19 +954,6 @@ PHP_MINFO_FUNCTION(mysqli)
#if !defined(MYSQLI_USE_MYSQLND)
php_info_print_table_row(2, "Client API header version", MYSQL_SERVER_VERSION);
php_info_print_table_row(2, "MYSQLI_SOCKET", MYSQL_UNIX_ADDR);
#else
{
zval values;
php_info_print_table_header(2, "Persistent cache", mysqli_mysqlnd_zval_cache? "enabled":"disabled");
if (mysqli_mysqlnd_zval_cache) {
/* Now report cache status */
mysqlnd_palloc_stats(mysqli_mysqlnd_zval_cache, &values);
mysqlnd_minfo_print_hash(&values);
zval_dtor(&values);
}
}
#endif
php_info_print_table_end();
@@ -1093,11 +1055,6 @@ PHP_FUNCTION(mysqli_result_construct)
case MYSQLI_USE_RESULT:
result = mysql_use_result(mysql->mysql);
break;
#if defined(MYSQLI_USE_MYSQLND) && defined(MYSQLND_THREADED)
case MYSQLI_BG_STORE_RESULT:
result = mysqli_bg_store_result(mysql->mysql);
break;
#endif
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for resultmode");
}
-1
View File
@@ -37,7 +37,6 @@
#define mysqli_close(c, how) mysqlnd_close((c), (how))
#define mysqli_stmt_close(c, implicit) mysqlnd_stmt_close((c), (implicit))
#define mysqli_free_result(r, implicit) mysqlnd_free_result((r), (implicit))
#define mysqli_bg_store_result(r) mysqlnd_bg_store_result((r))
#define mysqli_async_query(c, q, l) mysqlnd_async_query((c), (q), (l))
#define mysqli_change_user_silent(c, u, p, d) mysqlnd_change_user((c), (u), (p), (d), TRUE)
+4 -18
View File
@@ -175,7 +175,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
if (!mysql_ping(mysql->mysql)) {
#endif
#ifdef MYSQLI_USE_MYSQLND
mysqlnd_restart_psession(mysql->mysql, MyG(mysqlnd_thd_zval_cache));
mysqlnd_restart_psession(mysql->mysql);
#endif
MyG(num_active_persistent)++;
goto end;
@@ -232,7 +232,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
if (mysql_real_connect(mysql->mysql, hostname, username, passwd, dbname, port, socket, CLIENT_MULTI_RESULTS) == NULL)
#else
if (mysqlnd_connect(mysql->mysql, hostname, username, passwd, passwd_len, dbname, dbname_len,
port, socket, flags, MyG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
port, socket, flags TSRMLS_CC) == NULL)
#endif
{
/* Save error messages - for mysqli_connect_error() & mysqli_connect_errno() */
@@ -416,7 +416,7 @@ PHP_FUNCTION(mysqli_get_cache_stats)
if (zend_parse_parameters_none() == FAILURE) {
return;
}
mysqlnd_palloc_stats(mysqli_mysqlnd_zval_cache, return_value);
array_init(return_value);
}
/* }}} */
@@ -524,11 +524,7 @@ PHP_FUNCTION(mysqli_query)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty query");
RETURN_FALSE;
}
if ((resultmode & ~MYSQLI_ASYNC) != MYSQLI_USE_RESULT && (resultmode & ~MYSQLI_ASYNC) != MYSQLI_STORE_RESULT
#if defined(MYSQLI_USE_MYSQLND) && defined(MYSQLND_THREADED)
&& (resultmode & ~MYSQLI_ASYNC) != MYSQLI_BG_STORE_RESULT
#endif
) {
if ((resultmode & ~MYSQLI_ASYNC) != MYSQLI_USE_RESULT && (resultmode & ~MYSQLI_ASYNC) != MYSQLI_STORE_RESULT) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for resultmode");
RETURN_FALSE;
}
@@ -569,11 +565,6 @@ PHP_FUNCTION(mysqli_query)
case MYSQLI_USE_RESULT:
result = mysql_use_result(mysql->mysql);
break;
#if defined(MYSQLI_USE_MYSQLND) && defined(MYSQLND_THREADED)
case MYSQLI_BG_STORE_RESULT:
result = mysqli_bg_store_result(mysql->mysql);
break;
#endif
}
if (!result) {
php_mysqli_throw_sql_exception((char *)mysql_sqlstate(mysql->mysql), mysql_errno(mysql->mysql) TSRMLS_CC,
@@ -807,11 +798,6 @@ PHP_FUNCTION(mysqli_reap_async_query)
case MYSQLI_USE_RESULT:
result = mysql_use_result(mysql->mysql);
break;
#if defined(MYSQLI_USE_MYSQLND) && defined(MYSQLND_THREADED)
case MYSQLI_BG_STORE_RESULT:
result = mysqli_bg_store_result(mysql->mysql);
break;
#endif
}
if (!result) {
-11
View File
@@ -196,11 +196,6 @@ extern zend_property_info mysqli_stmt_property_info_entries[];
extern zend_property_info mysqli_driver_property_info_entries[];
extern zend_property_info mysqli_warning_property_info_entries[];
#ifdef MYSQLI_USE_MYSQLND
extern MYSQLND_ZVAL_PCACHE *mysqli_mysqlnd_zval_cache;
extern MYSQLND_QCACHE *mysqli_mysqlnd_qcache;
#endif
extern void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flag, int into_object);
extern void php_clear_stmt_bind(MY_STMT *stmt TSRMLS_DC);
extern void php_clear_mysql(MY_MYSQL *);
@@ -308,9 +303,6 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML
#define MYSQLI_STORE_RESULT 0
#define MYSQLI_USE_RESULT 1
#ifdef MYSQLI_USE_MYSQLND
#ifdef MYSQLND_THREADED
#define MYSQLI_BG_STORE_RESULT 4
#endif
#define MYSQLI_ASYNC 8
#else
/* libmysql */
@@ -370,9 +362,6 @@ ZEND_BEGIN_MODULE_GLOBALS(mysqli)
HashTable *report_ht;
unsigned long multi_query;
unsigned long embedded;
#ifdef MYSQLI_USE_MYSQLND
MYSQLND_THD_ZVAL_PCACHE *mysqlnd_thd_zval_cache;
#endif
ZEND_END_MODULE_GLOBALS(mysqli)
+2 -2
View File
@@ -55,7 +55,7 @@ object(mysqli)#%d (%d) {
[%u|b%"connect_errno"]=>
int(0)
[%u|b%"connect_error"]=>
%unicode|string%(0) ""
NULL
[%u|b%"errno"]=>
int(0)
[%u|b%"error"]=>
@@ -91,7 +91,7 @@ object(mysqli)#%d (%d) {
[%u|b%"connect_errno"]=>
int(0)
[%u|b%"connect_error"]=>
%unicode|string%(0) ""
NULL
[%u|b%"errno"]=>
int(0)
[%u|b%"error"]=>
@@ -276,6 +276,6 @@ setting mysqli->unknown, mysqli_unknown = '13'
setting mysqli->unknown, mysqli_unknown = 'friday'
Access hidden properties for MYSLQI_STATUS_INITIALIZED (TODO documentation):
mysqli->connect_error = ''/%unicode|string% (''/%unicode|string%)
mysqli->connect_error = ''/NULL (''/NULL)
mysqli->connect_errno = '0'/integer ('0'/integer)
done!
+2 -2
View File
@@ -21,8 +21,8 @@ require_once('skipifconnectfailure.inc');
printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);
if ('' !== ($tmp = mysqli_connect_error()))
printf("[003] Expecting string/'', got %s/%s\n", gettype($tmp), $tmp);
if (NULL !== ($tmp = mysqli_connect_error()))
printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
mysqli_close($link);
@@ -0,0 +1,93 @@
--TEST--
INSERT and packet overflow
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
?>
--INI--
memory_limit=256M
--FILE--
<?php
require('connect.inc');
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
if (!$res = mysqli_query($link, "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'"))
printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
if (!$row = mysqli_fetch_assoc($res))
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
mysqli_free_result($res);
if (0 === ($org_max_allowed_packet = (int)$row['Value']))
printf("[004] Cannot determine max_allowed_packet size and/or bogus max_allowed_packet setting used.\n");
$max_len = pow(2, 24);
if ($org_max_allowed_packet < $max_len) {
if (!mysqli_query($link, "SET GLOBAL max_allowed_packet = " . ($max_len + 100)))
printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
mysqli_close($link);
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
printf("[006] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
if (!$res = mysqli_query($link, "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'"))
printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
if (!$row = mysqli_fetch_assoc($res))
printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
mysqli_free_result($res);
if (0 === ($max_allowed_packet = (int)$row['Value']))
printf("[009] Cannot determine max_allowed_packet size and/or bogus max_allowed_packet setting used.\n");
$max_len = pow(2, 24);
if ($max_allowed_packet < $max_len) {
printf("[010] Failed to change max_allowed_packet");
}
if (!mysqli_query($link, "CREATE TABLE test(col_blob LONGBLOB) ENGINE=" . $engine))
printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
$query_prefix = 'INSERT INTO test(col_blob) VALUES ("';
$query_postfix = '")';
$query_len = strlen($query_prefix) + strlen($query_postfix);
$com_query_len = 1;
$blob = str_repeat('a', $max_len - $com_query_len - $query_len);
$query = sprintf("%s%s%s", $query_prefix, $blob, $query_postfix);
if (!mysqli_query($link, $query))
printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
if (!$res = mysqli_query($link, "SELECT col_blob FROM test"))
printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
if (!$row = mysqli_fetch_assoc($res)) {
printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
} else {
if ($row['col_blob'] != $blob) {
printf("[015] Blob seems wrong, dumping data\n");
var_dump(strlen($row['col_blob']));
var_dump(strlen($blob));
}
mysqli_free_result($res);
}
if (!mysqli_query($link, "SET GLOBAL max_allowed_packet = " . $org_max_allowed_packet))
printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
mysqli_close($link);
print "done!";
?>
--CLEAN--
<?php
require_once("clean_table.inc");
?>
--EXPECTF--
done!
+1 -1
View File
@@ -91,7 +91,7 @@ object(mysqli)#%d (%d) {
[%u|b%"connect_errno"]=>
int(0)
[%u|b%"connect_error"]=>
%unicode|string%(0) ""
NULL
[%u|b%"errno"]=>
int(2006)
[%u|b%"error"]=>
+1 -2
View File
@@ -11,10 +11,9 @@ if (PHP_MYSQLND != "no") {
"mysqlnd_charset.c " +
"mysqlnd_debug.c " +
"mysqlnd_loaddata.c " +
"mysqlnd_palloc.c " +
"mysqlnd_net.c " +
"mysqlnd_ps.c " +
"mysqlnd_ps_codec.c " +
"mysqlnd_qcache.c " +
"mysqlnd_result.c " +
"mysqlnd_result_meta.c " +
"mysqlnd_statistics.c " +
+3 -11
View File
@@ -3,11 +3,6 @@ dnl $Id$
dnl config.m4 for mysqlnd driver
PHP_ARG_ENABLE(mysqlnd_threading, whether to enable threaded fetch in mysqlnd,
[ --enable-mysqlnd-threading
EXPERIMENTAL: Enable mysqlnd threaded fetch.
Note: This forces ZTS on!], no, no)
PHP_ARG_ENABLE(disable_mysqlnd_compression_support, whether to disable compressed protocol support in mysqlnd,
[ --disable-mysqlnd-compression-support
Enable support for the MySQL compressed protocol in mysqlnd], yes)
@@ -20,19 +15,16 @@ fi
dnl If some extension uses mysqlnd it will get compiled in PHP core
if test "$PHP_MYSQLND_ENABLED" = "yes"; then
mysqlnd_sources="mysqlnd.c mysqlnd_charset.c mysqlnd_wireprotocol.c \
mysqlnd_ps.c mysqlnd_loaddata.c mysqlnd_palloc.c \
mysqlnd_ps_codec.c mysqlnd_statistics.c mysqlnd_qcache.c\
mysqlnd_ps.c mysqlnd_loaddata.c mysqlnd_net.c \
mysqlnd_ps_codec.c mysqlnd_statistics.c \
mysqlnd_result.c mysqlnd_result_meta.c mysqlnd_debug.c\
mysqlnd_block_alloc.c php_mysqlnd.c"
PHP_NEW_EXTENSION(mysqlnd, $mysqlnd_sources, no)
PHP_ADD_BUILD_DIR([ext/mysqlnd], 1)
PHP_INSTALL_HEADERS([ext/mysqlnd/])
dnl Windows uses config.w32 thus this code is safe for now
if test "$PHP_MYSQLND_THREADING" = "yes"; then
PHP_BUILD_THREAD_SAFE
AC_DEFINE([MYSQLND_THREADED], 1, [Use mysqlnd internal threading])
fi
if test "$PHP_MYSQLND_COMPRESSION_SUPPORT" != "no"; then
AC_DEFINE([MYSQLND_COMPRESSION_ENABLED], 1, [Enable compressed protocol support])
+77 -307
View File
@@ -145,23 +145,10 @@ MYSQLND_METHOD(mysqlnd_conn, free_contents)(MYSQLND *conn TSRMLS_DC)
conn->current_result = NULL;
}
if (conn->net.stream) {
DBG_INF_FMT("Freeing stream. abstract=%p", conn->net.stream->abstract);
if (pers) {
php_stream_free(conn->net.stream, PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR);
} else {
php_stream_free(conn->net.stream, PHP_STREAM_FREE_CLOSE);
}
conn->net.stream = NULL;
}
#ifdef MYSQLND_COMPRESSION_ENABLED
if (conn->net.uncompressed_data) {
conn->net.uncompressed_data->free_buffer(&conn->net.uncompressed_data TSRMLS_CC);
}
#endif
conn->net->m.free_contents(conn->net TSRMLS_CC);
DBG_INF("Freeing memory of members");
if (conn->host) {
DBG_INF("Freeing host");
mnd_pefree(conn->host, pers);
@@ -211,22 +198,6 @@ MYSQLND_METHOD(mysqlnd_conn, free_contents)(MYSQLND *conn TSRMLS_DC)
mnd_pefree(conn->last_message, pers);
conn->last_message = NULL;
}
if (conn->zval_cache) {
DBG_INF("Freeing zval cache reference");
mysqlnd_palloc_free_thd_cache_reference(&conn->zval_cache);
conn->zval_cache = NULL;
}
if (conn->qcache) {
DBG_INF("Freeing qcache reference");
mysqlnd_qcache_free_cache_reference(&conn->qcache);
conn->qcache = NULL;
}
if (conn->net.cmd_buffer.buffer) {
DBG_INF("Freeing cmd buffer");
mnd_pefree(conn->net.cmd_buffer.buffer, pers);
conn->net.cmd_buffer.buffer = NULL;
}
conn->charset = NULL;
conn->greet_charset = NULL;
@@ -245,22 +216,12 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_conn, dtor)(MYSQLND *conn TSRMLS_DC)
conn->m->free_contents(conn TSRMLS_CC);
conn->m->free_options(conn TSRMLS_CC);
#ifdef MYSQLND_THREADED
if (conn->thread_is_running) {
pthread_mutex_lock(&conn->LOCK_work);
conn->thread_killed = TRUE;
pthread_cond_signal(&conn->COND_work);
pthread_cond_wait(&conn->COND_thread_ended, &conn->LOCK_work);
pthread_mutex_unlock(&conn->LOCK_work);
if (conn->net) {
DBG_INF("Freeing net");
mysqlnd_net_free(conn->net TSRMLS_CC);
conn->net = NULL;
}
tsrm_mutex_free(conn->LOCK_state);
pthread_cond_destroy(&conn->COND_work);
pthread_cond_destroy(&conn->COND_work_done);
pthread_mutex_destroy(&conn->LOCK_work);
#endif
mnd_pefree(conn, conn->persistent);
DBG_VOID_RETURN;
@@ -268,16 +229,15 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_conn, dtor)(MYSQLND *conn TSRMLS_DC)
/* }}} */
/* {{{ mysqlnd_simple_command_handle_response */
enum_func_status
mysqlnd_simple_command_handle_response(MYSQLND *conn, enum php_mysql_packet_type ok_packet,
zend_bool silent, enum php_mysqlnd_server_command command,
zend_bool ignore_upsert_status
TSRMLS_DC)
/* {{{ mysqlnd_conn::simple_command_handle_response */
static enum_func_status
MYSQLND_METHOD(mysqlnd_conn, simple_command_handle_response)(MYSQLND *conn, enum php_mysql_packet_type ok_packet,
zend_bool silent, enum php_mysqlnd_server_command command,
zend_bool ignore_upsert_status TSRMLS_DC)
{
enum_func_status ret;
DBG_ENTER("mysqlnd_simple_command_handle_response");
DBG_ENTER("mysqlnd_conn::simple_command_handle_response");
DBG_INF_FMT("silent=%d packet=%d command=%s", silent, ok_packet, mysqlnd_command_to_text[command]);
switch (ok_packet) {
@@ -369,17 +329,16 @@ mysqlnd_simple_command_handle_response(MYSQLND *conn, enum php_mysql_packet_type
/* }}} */
/* {{{ mysqlnd_simple_command */
enum_func_status
mysqlnd_simple_command(MYSQLND *conn, enum php_mysqlnd_server_command command,
const char * const arg, size_t arg_len,
enum php_mysql_packet_type ok_packet, zend_bool silent,
zend_bool ignore_upsert_status TSRMLS_DC)
/* {{{ mysqlnd_conn::simple_command */
static enum_func_status
MYSQLND_METHOD(mysqlnd_conn, simple_command)(MYSQLND *conn, enum php_mysqlnd_server_command command,
const char * const arg, size_t arg_len, enum php_mysql_packet_type ok_packet, zend_bool silent,
zend_bool ignore_upsert_status TSRMLS_DC)
{
enum_func_status ret = PASS;
php_mysql_packet_command cmd_packet;
DBG_ENTER("mysqlnd_simple_command");
DBG_ENTER("mysqlnd_conn::simple_command");
DBG_INF_FMT("command=%s ok_packet=%d silent=%d", mysqlnd_command_to_text[command], ok_packet, silent);
switch (CONN_GET_STATE(conn)) {
@@ -420,7 +379,7 @@ mysqlnd_simple_command(MYSQLND *conn, enum php_mysqlnd_server_command command,
DBG_ERR("Server is gone");
ret = FAIL;
} else if (ok_packet != PROT_LAST) {
ret = mysqlnd_simple_command_handle_response(conn, ok_packet, silent, command, ignore_upsert_status TSRMLS_CC);
ret = conn->m->simple_command_handle_response(conn, ok_packet, silent, command, ignore_upsert_status TSRMLS_CC);
}
/*
@@ -445,15 +404,14 @@ MYSQLND_METHOD(mysqlnd_conn, set_server_option)(MYSQLND * const conn,
DBG_ENTER("mysqlnd_conn::set_server_option");
int2store(buffer, (unsigned int) option);
ret = mysqlnd_simple_command(conn, COM_SET_OPTION, buffer, sizeof(buffer),
PROT_EOF_PACKET, FALSE, TRUE TSRMLS_CC);
ret = conn->m->simple_command(conn, COM_SET_OPTION, buffer, sizeof(buffer), PROT_EOF_PACKET, FALSE, TRUE TSRMLS_CC);
DBG_RETURN(ret);
}
/* }}} */
/* {{{ _mysqlnd_restart_psession */
PHPAPI void _mysqlnd_restart_psession(MYSQLND *conn, MYSQLND_THD_ZVAL_PCACHE *cache TSRMLS_DC)
PHPAPI void _mysqlnd_restart_psession(MYSQLND *conn TSRMLS_DC)
{
DBG_ENTER("_mysqlnd_restart_psession");
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_CONNECT_REUSED);
@@ -466,7 +424,6 @@ PHPAPI void _mysqlnd_restart_psession(MYSQLND *conn, MYSQLND_THD_ZVAL_PCACHE *ca
The thd zval cache is always freed on request shutdown, so this has happened already.
Don't touch the old value! Get new reference
*/
conn->zval_cache = mysqlnd_palloc_get_thd_cache_reference(cache);
DBG_VOID_RETURN;
}
/* }}} */
@@ -476,8 +433,6 @@ PHPAPI void _mysqlnd_restart_psession(MYSQLND *conn, MYSQLND_THD_ZVAL_PCACHE *ca
PHPAPI void _mysqlnd_end_psession(MYSQLND *conn TSRMLS_DC)
{
DBG_ENTER("_mysqlnd_end_psession");
/* The thd zval cache is always freed on request shutdown, so this has happened already */
mysqlnd_palloc_free_thd_cache_reference(&conn->zval_cache);
DBG_VOID_RETURN;
}
/* }}} */
@@ -491,17 +446,12 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND *conn,
const char *db, unsigned int db_len,
unsigned int port,
const char *socket,
unsigned int mysql_flags,
MYSQLND_THD_ZVAL_PCACHE *zval_cache
unsigned int mysql_flags
TSRMLS_DC)
{
char *transport = NULL, *errstr = NULL;
char *hashed_details = NULL;
int transport_len, hashed_details_len, errcode = 0, host_len;
unsigned int streams_options = ENFORCE_SAFE_MODE;
unsigned int streams_flags = STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT;
int transport_len, errcode = 0, host_len;
zend_bool self_alloced = FALSE;
struct timeval tv;
zend_bool unix_socket = FALSE;
const MYSQLND_CHARSET * charset;
zend_bool reconnect = FALSE;
@@ -533,14 +483,14 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND *conn,
MYSQLND_DEC_CONN_STATISTIC(&conn->stats, STAT_OPENED_PERSISTENT_CONNECTIONS);
}
/* Now reconnect using the same handle */
if (conn->net.compressed) {
if (conn->net->compressed) {
/*
we need to save the state. As we will re-connect, net.compressed should be off, or
we need to save the state. As we will re-connect, net->compressed should be off, or
we will look for a compression header as part of the greet message, but there will
be none.
*/
saved_compression = TRUE;
conn->net.compressed = FALSE;
conn->net->compressed = FALSE;
}
}
@@ -581,88 +531,19 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND *conn,
PACKET_INIT(auth_packet, PROT_AUTH_PACKET, php_mysql_packet_auth *, FALSE);
PACKET_INIT_ALLOCA(ok_packet, PROT_OK_PACKET);
if (conn->persistent) {
hashed_details_len = spprintf(&hashed_details, 0, "%p", conn);
DBG_INF_FMT("hashed_details=%s", hashed_details);
}
CONN_SET_STATE(conn, CONN_ALLOCED);
conn->net.packet_no = conn->net.compressed_envelope_packet_no = 0;
if (conn->options.timeout_connect) {
tv.tv_sec = conn->options.timeout_connect;
tv.tv_usec = 0;
}
if (conn->persistent) {
conn->scheme = pestrndup(transport, transport_len, 1);
mnd_efree(transport);
} else {
conn->scheme = transport;
}
conn->scheme_len = strlen(conn->scheme);
conn->scheme_len = transport_len;
DBG_INF(conn->scheme);
conn->net.stream = php_stream_xport_create(conn->scheme, transport_len, streams_options, streams_flags,
hashed_details,
(conn->options.timeout_connect) ? &tv : NULL,
NULL /*ctx*/, &errstr, &errcode);
DBG_INF_FMT("stream=%p", conn->net.stream);
if (errstr || !conn->net.stream) {
if (hashed_details) {
mnd_efree(hashed_details);
}
errcode = CR_CONNECTION_ERROR;
goto err;
}
if (hashed_details) {
/*
If persistent, the streams register it in EG(persistent_list).
This is unwanted. ext/mysql or ext/mysqli are responsible to clean,
whatever they have to.
*/
zend_rsrc_list_entry *le;
if (zend_hash_find(&EG(persistent_list), hashed_details, hashed_details_len + 1,
(void*) &le) == SUCCESS) {
/*
in_free will let streams code skip destructing - big HACK,
but STREAMS suck big time regarding persistent streams.
Just not compatible for extensions that need persistency.
*/
conn->net.stream->in_free = 1;
zend_hash_del(&EG(persistent_list), hashed_details, hashed_details_len + 1);
conn->net.stream->in_free = 0;
}
#if ZEND_DEBUG
/* Shut-up the streams, they don't know what they are doing */
conn->net.stream->__exposed = 1;
#endif
mnd_efree(hashed_details);
}
if (!conn->options.timeout_read) {
/* should always happen because read_timeout cannot be set via API */
conn->options.timeout_read = (unsigned int) MYSQLND_G(net_read_timeout);
}
if (conn->options.timeout_read)
{
tv.tv_sec = conn->options.timeout_read;
tv.tv_usec = 0;
php_stream_set_option(conn->net.stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &tv);
}
if (!unix_socket) {
/* Set TCP_NODELAY */
mysqlnd_set_sock_no_delay(conn->net.stream);
}
{
unsigned int buf_size;
buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/
conn->m->set_client_option(conn, MYSQLND_OPT_NET_READ_BUFFER_SIZE, (char *)&buf_size TSRMLS_CC);
if (FAIL == conn->net->m.connect(conn->net, conn->scheme, transport_len, conn->persistent, &errstr, &errcode TSRMLS_CC)) {
goto err;
}
DBG_INF_FMT("stream=%p", conn->net->stream);
if (FAIL == PACKET_READ_ALLOCA(greet_packet, conn)) {
DBG_ERR("Error while reading greeting packet");
@@ -744,14 +625,14 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND *conn,
} else {
CONN_SET_STATE(conn, CONN_READY);
if (!self_alloced && saved_compression) {
conn->net.compressed = TRUE;
conn->net->compressed = TRUE;
}
/*
If a connect on a existing handle is performed and mysql_flags is
passed which doesn't CLIENT_COMPRESS, then we need to overwrite the value
which we set based on saved_compression.
*/
conn->net.compressed = mysql_flags & CLIENT_COMPRESS? TRUE:FALSE;
conn->net->compressed = mysql_flags & CLIENT_COMPRESS? TRUE:FALSE;
conn->user = pestrdup(user, conn->persistent);
conn->user_len = strlen(conn->user);
@@ -792,18 +673,10 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND *conn,
SET_EMPTY_ERROR(conn->error_info);
conn->zval_cache = mysqlnd_palloc_get_thd_cache_reference(zval_cache);
mysqlnd_local_infile_default(conn);
{
unsigned int buf_size;
buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/
conn->m->set_client_option(conn, MYSQLND_OPT_NET_READ_BUFFER_SIZE,
(char *)&buf_size TSRMLS_CC);
buf_size = MYSQLND_G(net_cmd_buffer_size); /* this is long, cast to unsigned int*/
conn->m->set_client_option(conn, MYSQLND_OPT_NET_CMD_BUFFER_SIZE,
(char *)&buf_size TSRMLS_CC);
unsigned int buf_size = MYSQLND_G(net_cmd_buffer_size); /* this is long, cast to unsigned int*/
conn->m->set_client_option(conn, MYSQLND_OPT_NET_CMD_BUFFER_SIZE, (char *)&buf_size TSRMLS_CC);
}
MYSQLND_INC_CONN_STATISTIC_W_VALUE2(&conn->stats, STAT_CONNECT_SUCCESS, 1, STAT_OPENED_CONNECTIONS, 1);
@@ -823,21 +696,6 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND *conn,
DBG_INF("unicode set");
}
#endif
#ifdef MYSQLND_THREADED
{
pthread_t th;
pthread_attr_t connection_attrib;
conn->tsrm_ls = tsrm_ls;
pthread_attr_init(&connection_attrib);
pthread_attr_setdetachstate(&connection_attrib, PTHREAD_CREATE_DETACHED);
conn->thread_is_running = TRUE;
if (pthread_create(&th, &connection_attrib, mysqlnd_fetch_thread, (void*)conn)) {
conn->thread_is_running = FALSE;
}
}
#endif
if (conn->options.init_commands) {
int current_command = 0;
@@ -879,8 +737,6 @@ err:
conn->scheme = NULL;
}
/* This will also close conn->net.stream if it has been opened */
conn->m->free_contents(conn TSRMLS_CC);
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_CONNECT_FAILURE);
DBG_RETURN(FAIL);
@@ -895,8 +751,7 @@ PHPAPI MYSQLND * mysqlnd_connect(MYSQLND * conn,
const char *db, unsigned int db_len,
unsigned int port,
const char *socket,
unsigned int mysql_flags,
MYSQLND_THD_ZVAL_PCACHE *zval_cache
unsigned int mysql_flags
TSRMLS_DC)
{
enum_func_status ret;
@@ -910,7 +765,7 @@ PHPAPI MYSQLND * mysqlnd_connect(MYSQLND * conn,
self_alloced = TRUE;
}
ret = conn->m->connect(conn, host, user, passwd, passwd_len, db, db_len, port, socket, mysql_flags, zval_cache TSRMLS_CC);
ret = conn->m->connect(conn, host, user, passwd, passwd_len, db, db_len, port, socket, mysql_flags TSRMLS_CC);
if (ret == FAIL) {
if (self_alloced) {
@@ -919,6 +774,9 @@ PHPAPI MYSQLND * mysqlnd_connect(MYSQLND * conn,
object - we are free to kill it!
*/
conn->m->dtor(conn TSRMLS_CC);
} else {
/* This will also close conn->net->stream if it has been opened */
conn->m->free_contents(conn TSRMLS_CC);
}
DBG_RETURN(NULL);
}
@@ -939,7 +797,7 @@ MYSQLND_METHOD(mysqlnd_conn, query)(MYSQLND *conn, const char *query, unsigned i
DBG_ENTER("mysqlnd_conn::query");
DBG_INF_FMT("conn=%llu query=%s", conn->thread_id, query);
if (PASS != mysqlnd_simple_command(conn, COM_QUERY, query, query_len,
if (PASS != conn->m->simple_command(conn, COM_QUERY, query, query_len,
PROT_LAST /* we will handle the OK packet*/,
FALSE, FALSE TSRMLS_CC)) {
DBG_RETURN(FAIL);
@@ -967,7 +825,7 @@ MYSQLND_METHOD(mysqlnd_conn, send_query)(MYSQLND *conn, const char *query, unsig
DBG_ENTER("mysqlnd_conn::send_query");
DBG_INF_FMT("conn=%llu query=%s", conn->thread_id, query);
ret = mysqlnd_simple_command(conn, COM_QUERY, query, query_len,
ret = conn->m->simple_command(conn, COM_QUERY, query, query_len,
PROT_LAST /* we will handle the OK packet*/,
FALSE, FALSE TSRMLS_CC);
CONN_SET_STATE(conn, CONN_QUERY_SENT);
@@ -1039,7 +897,7 @@ static int mysqlnd_stream_array_to_fd_set(MYSQLND **conn_array, fd_set *fds, php
* when casting. It is only used here so that the buffered data warning
* is not displayed.
* */
if (SUCCESS == php_stream_cast((*p)->net.stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL,
if (SUCCESS == php_stream_cast((*p)->net->stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL,
(void*)&this_fd, 1) && this_fd >= 0) {
PHP_SAFE_FD_SET(this_fd, fds);
@@ -1064,7 +922,7 @@ static int mysqlnd_stream_array_from_fd_set(MYSQLND **conn_array, fd_set *fds TS
MYSQLND **fwd = conn_array, **bckwd = conn_array;
while (*fwd) {
if (SUCCESS == php_stream_cast((*fwd)->net.stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL,
if (SUCCESS == php_stream_cast((*fwd)->net->stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL,
(void*)&this_fd, 1) && this_fd >= 0) {
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
if (disproportion) {
@@ -1202,7 +1060,7 @@ MYSQLND_METHOD(mysqlnd_conn, list_fields)(MYSQLND *conn, const char *table, cons
*p++ = '\0';
}
if (PASS != mysqlnd_simple_command(conn, COM_FIELD_LIST, buff, p - buff,
if (PASS != conn->m->simple_command(conn, COM_FIELD_LIST, buff, p - buff,
PROT_LAST /* we will handle the OK packet*/,
FALSE, TRUE TSRMLS_CC)) {
DBG_RETURN(NULL);
@@ -1211,7 +1069,7 @@ MYSQLND_METHOD(mysqlnd_conn, list_fields)(MYSQLND *conn, const char *table, cons
Prepare for the worst case.
MyISAM goes to 2500 BIT columns, double it for safety.
*/
result = mysqlnd_result_init(5000, mysqlnd_palloc_get_thd_cache_reference(conn->zval_cache) TSRMLS_CC);
result = mysqlnd_result_init(5000 TSRMLS_CC);
if (FAIL == result->m.read_result_metadata(result, conn TSRMLS_CC)) {
@@ -1325,7 +1183,7 @@ MYSQLND_METHOD(mysqlnd_conn, dump_debug_info)(MYSQLND * const conn TSRMLS_DC)
{
DBG_ENTER("mysqlnd_conn::dump_debug_info");
DBG_INF_FMT("conn=%llu", conn->thread_id);
DBG_RETURN(mysqlnd_simple_command(conn, COM_DEBUG, NULL, 0, PROT_EOF_PACKET, FALSE, TRUE TSRMLS_CC));
DBG_RETURN(conn->m->simple_command(conn, COM_DEBUG, NULL, 0, PROT_EOF_PACKET, FALSE, TRUE TSRMLS_CC));
}
/* }}} */
@@ -1341,7 +1199,7 @@ MYSQLND_METHOD(mysqlnd_conn, select_db)(MYSQLND * const conn,
DBG_ENTER("mysqlnd_conn::select_db");
DBG_INF_FMT("conn=%llu db=%s", conn->thread_id, db);
ret = mysqlnd_simple_command(conn, COM_INIT_DB, db, db_len, PROT_OK_PACKET, FALSE, TRUE TSRMLS_CC);
ret = conn->m->simple_command(conn, COM_INIT_DB, db, db_len, PROT_OK_PACKET, FALSE, TRUE TSRMLS_CC);
/*
The server sends 0 but libmysql doesn't read it and has established
a protocol of giving back -1. Thus we have to follow it :(
@@ -1368,7 +1226,7 @@ MYSQLND_METHOD(mysqlnd_conn, ping)(MYSQLND * const conn TSRMLS_DC)
DBG_ENTER("mysqlnd_conn::ping");
DBG_INF_FMT("conn=%llu", conn->thread_id);
ret = mysqlnd_simple_command(conn, COM_PING, NULL, 0, PROT_OK_PACKET, TRUE, TRUE TSRMLS_CC);
ret = conn->m->simple_command(conn, COM_PING, NULL, 0, PROT_OK_PACKET, TRUE, TRUE TSRMLS_CC);
/*
The server sends 0 but libmysql doesn't read it and has established
a protocol of giving back -1. Thus we have to follow it :(
@@ -1391,7 +1249,7 @@ MYSQLND_METHOD(mysqlnd_conn, stat)(MYSQLND *conn, char **message, unsigned int *
DBG_ENTER("mysqlnd_conn::stat");
DBG_INF_FMT("conn=%llu", conn->thread_id);
ret = mysqlnd_simple_command(conn, COM_STATISTICS, NULL, 0, PROT_LAST, FALSE, TRUE TSRMLS_CC);
ret = conn->m->simple_command(conn, COM_STATISTICS, NULL, 0, PROT_LAST, FALSE, TRUE TSRMLS_CC);
if (FAIL == ret) {
DBG_RETURN(FAIL);
}
@@ -1425,13 +1283,13 @@ MYSQLND_METHOD(mysqlnd_conn, kill)(MYSQLND *conn, unsigned int pid TSRMLS_DC)
/* If we kill ourselves don't expect OK packet, PROT_LAST will skip it */
if (pid != conn->thread_id) {
ret = mysqlnd_simple_command(conn, COM_PROCESS_KILL, buff, 4, PROT_OK_PACKET, FALSE, TRUE TSRMLS_CC);
ret = conn->m->simple_command(conn, COM_PROCESS_KILL, buff, 4, PROT_OK_PACKET, FALSE, TRUE TSRMLS_CC);
/*
The server sends 0 but libmysql doesn't read it and has established
a protocol of giving back -1. Thus we have to follow it :(
*/
SET_ERROR_AFF_ROWS(conn);
} else if (PASS == (ret = mysqlnd_simple_command(conn, COM_PROCESS_KILL, buff,
} else if (PASS == (ret = conn->m->simple_command(conn, COM_PROCESS_KILL, buff,
4, PROT_LAST, FALSE, TRUE TSRMLS_CC))) {
CONN_SET_STATE(conn, CONN_QUIT_SENT);
}
@@ -1485,7 +1343,7 @@ MYSQLND_METHOD(mysqlnd_conn, refresh)(MYSQLND * const conn, uint8_t options TSRM
int1store(bits, options);
DBG_RETURN(mysqlnd_simple_command(conn, COM_REFRESH, (char *)bits, 1, PROT_OK_PACKET, FALSE, TRUE TSRMLS_CC));
DBG_RETURN(conn->m->simple_command(conn, COM_REFRESH, (char *)bits, 1, PROT_OK_PACKET, FALSE, TRUE TSRMLS_CC));
}
/* }}} */
@@ -1500,7 +1358,7 @@ MYSQLND_METHOD(mysqlnd_conn, shutdown)(MYSQLND * const conn, uint8_t level TSRML
int1store(bits, level);
DBG_RETURN(mysqlnd_simple_command(conn, COM_SHUTDOWN, (char *)bits, 1, PROT_OK_PACKET, FALSE, TRUE TSRMLS_CC));
DBG_RETURN(conn->m->simple_command(conn, COM_SHUTDOWN, (char *)bits, 1, PROT_OK_PACKET, FALSE, TRUE TSRMLS_CC));
}
/* }}} */
@@ -1512,14 +1370,14 @@ mysqlnd_send_close(MYSQLND * conn TSRMLS_DC)
enum_func_status ret = PASS;
DBG_ENTER("mysqlnd_send_close");
DBG_INF_FMT("conn=%llu conn->net.stream->abstract=%p",
conn->thread_id, conn->net.stream? conn->net.stream->abstract:NULL);
DBG_INF_FMT("conn=%llu conn->net->stream->abstract=%p",
conn->thread_id, conn->net->stream? conn->net->stream->abstract:NULL);
switch (CONN_GET_STATE(conn)) {
case CONN_READY:
DBG_INF("Connection clean, sending COM_QUIT");
if (conn->net.stream) {
ret = mysqlnd_simple_command(conn, COM_QUIT, NULL, 0, PROT_LAST, TRUE, TRUE TSRMLS_CC);
if (conn->net->stream) {
ret = conn->m->simple_command(conn, COM_QUIT, NULL, 0, PROT_LAST, TRUE, TRUE TSRMLS_CC);
}
/* Do nothing */
break;
@@ -1630,25 +1488,12 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_conn, free_reference)(MYSQLND * const conn TSRMLS
/* {{{ mysqlnd_conn::get_state */
#ifdef MYSQLND_THREADED
static enum mysqlnd_connection_state
MYSQLND_METHOD_PRIVATE(mysqlnd_conn, get_state)(MYSQLND * const conn TSRMLS_DC)
{
enum mysqlnd_connection_state state;
DBG_ENTER("mysqlnd_conn::get_state");
tsrm_mutex_lock(conn->LOCK_state);
state = conn->state;
tsrm_mutex_unlock(conn->LOCK_state);
DBG_RETURN(state);
}
#else
static enum mysqlnd_connection_state
MYSQLND_METHOD_PRIVATE(mysqlnd_conn, get_state)(MYSQLND * const conn TSRMLS_DC)
{
DBG_ENTER("mysqlnd_conn::get_state");
DBG_RETURN(conn->state);
}
#endif
/* }}} */
@@ -1657,14 +1502,8 @@ static void
MYSQLND_METHOD_PRIVATE(mysqlnd_conn, set_state)(MYSQLND * const conn, enum mysqlnd_connection_state new_state TSRMLS_DC)
{
DBG_ENTER("mysqlnd_conn::set_state");
#ifdef MYSQLND_THREADED
tsrm_mutex_lock(conn->LOCK_state);
#endif
DBG_INF_FMT("New state=%d", new_state);
conn->state = new_state;
#ifdef MYSQLND_THREADED
tsrm_mutex_unlock(conn->LOCK_state);
#endif
DBG_VOID_RETURN;
}
/* }}} */
@@ -1954,7 +1793,7 @@ MYSQLND_METHOD(mysqlnd_conn, change_user)(MYSQLND * const conn,
}
*p++ = '\0';
if (PASS != mysqlnd_simple_command(conn, COM_CHANGE_USER, buffer, p - buffer,
if (PASS != conn->m->simple_command(conn, COM_CHANGE_USER, buffer, p - buffer,
PROT_LAST /* we will handle the OK packet*/,
silent, TRUE TSRMLS_CC)) {
DBG_RETURN(FAIL);
@@ -2017,50 +1856,28 @@ MYSQLND_METHOD(mysqlnd_conn, set_client_option)(MYSQLND * const conn,
DBG_ENTER("mysqlnd_conn::set_client_option");
DBG_INF_FMT("conn=%llu option=%d", conn->thread_id, option);
switch (option) {
#ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_OPT_COMPRESS:
#endif
#ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_OPT_READ_TIMEOUT:
case MYSQL_OPT_WRITE_TIMEOUT:
#endif
case MYSQL_OPT_CONNECT_TIMEOUT:
case MYSQLND_OPT_NET_CMD_BUFFER_SIZE:
case MYSQLND_OPT_NET_READ_BUFFER_SIZE:
conn->net->m.set_client_option(conn->net, option, value TSRMLS_CC);
break;
#if PHP_MAJOR_VERSION >= 6
case MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE:
conn->options.numeric_and_datetime_as_unicode = *(unsigned int*) value;
break;
#endif
case MYSQLND_OPT_NET_CMD_BUFFER_SIZE:
DBG_INF("MYSQLND_OPT_NET_CMD_BUFFER_SIZE");
if (*(unsigned int*) value < MYSQLND_NET_CMD_BUFFER_MIN_SIZE) {
DBG_RETURN(FAIL);
}
conn->net.cmd_buffer.length = *(unsigned int*) value;
DBG_INF_FMT("new_length=%u", conn->net.cmd_buffer.length);
if (!conn->net.cmd_buffer.buffer) {
conn->net.cmd_buffer.buffer = mnd_pemalloc(conn->net.cmd_buffer.length, conn->persistent);
} else {
conn->net.cmd_buffer.buffer = mnd_perealloc(conn->net.cmd_buffer.buffer,
conn->net.cmd_buffer.length,
conn->persistent);
}
break;
case MYSQLND_OPT_NET_READ_BUFFER_SIZE:
DBG_INF("MYSQLND_OPT_NET_READ_BUFFER_SIZE");
conn->options.net_read_buffer_size = *(unsigned int*) value;
DBG_INF_FMT("new_length=%u", conn->options.net_read_buffer_size);
break;
#ifdef MYSQLND_STRING_TO_INT_CONVERSION
case MYSQLND_OPT_INT_AND_FLOAT_NATIVE:
DBG_INF("MYSQLND_OPT_INT_AND_FLOAT_NATIVE");
conn->options.int_and_float_native = *(unsigned int*) value;
break;
#endif
case MYSQL_OPT_CONNECT_TIMEOUT:
DBG_INF("MYSQL_OPT_CONNECT_TIMEOUT");
conn->options.timeout_connect = *(unsigned int*) value;
break;
#ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_OPT_READ_TIMEOUT:
DBG_INF("MYSQL_OPT_READ_TIMEOUT");
conn->options.timeout_read = *(unsigned int*) value;
break;
case MYSQL_OPT_WRITE_TIMEOUT:
DBG_INF("MYSQL_OPT_WRITE_TIMEOUT");
conn->options.timeout_write = *(unsigned int*) value;
break;
#endif
case MYSQL_OPT_LOCAL_INFILE:
DBG_INF("MYSQL_OPT_LOCAL_INFILE");
@@ -2079,9 +1896,6 @@ MYSQLND_METHOD(mysqlnd_conn, set_client_option)(MYSQLND * const conn,
conn->options.init_commands[conn->options.num_commands] = pestrdup(value, conn->persistent);
++conn->options.num_commands;
break;
#ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_OPT_COMPRESS:
#endif
case MYSQL_READ_DEFAULT_FILE:
case MYSQL_READ_DEFAULT_GROUP:
#ifdef WHEN_SUPPORTED_BY_MYSQLI
@@ -2190,44 +2004,6 @@ MYSQLND_METHOD(mysqlnd_conn, store_result)(MYSQLND * const conn TSRMLS_DC)
/* }}} */
/* {{{ mysqlnd_conn::background_store_result */
MYSQLND_RES *
MYSQLND_METHOD(mysqlnd_conn, background_store_result)(MYSQLND * const conn TSRMLS_DC)
{
MYSQLND_RES *result;
DBG_ENTER("mysqlnd_conn::store_result");
DBG_INF_FMT("conn=%llu", conn->thread_id);
if (!conn->current_result) {
DBG_RETURN(NULL);
}
/* Nothing to store for UPSERT/LOAD DATA*/
if (conn->last_query_type != QUERY_SELECT || CONN_GET_STATE(conn) != CONN_FETCHING_DATA) {
SET_CLIENT_ERROR(conn->error_info, CR_COMMANDS_OUT_OF_SYNC, UNKNOWN_SQLSTATE,
mysqlnd_out_of_sync);
DBG_ERR("Command out of sync");
DBG_RETURN(NULL);
}
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_BUFFERED_SETS);
result = conn->current_result;
result = result->m.background_store_result(result, conn, FALSE TSRMLS_CC);
/*
Should be here, because current_result is used by the fetching thread to get data info
The thread is contacted in mysqlnd_res::background_store_result().
*/
conn->current_result = NULL;
DBG_RETURN(result);
}
/* }}} */
/* {{{ mysqlnd_conn::get_connection_stats */
static void
MYSQLND_METHOD(mysqlnd_conn, get_connection_stats)(const MYSQLND * const conn,
@@ -2254,7 +2030,6 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_conn)
MYSQLND_METHOD(mysqlnd_conn, reap_query),
MYSQLND_METHOD(mysqlnd_conn, use_result),
MYSQLND_METHOD(mysqlnd_conn, store_result),
MYSQLND_METHOD(mysqlnd_conn, background_store_result),
MYSQLND_METHOD(mysqlnd_conn, next_result),
MYSQLND_METHOD(mysqlnd_conn, more_results),
@@ -2305,6 +2080,9 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_conn)
MYSQLND_METHOD_PRIVATE(mysqlnd_conn, free_reference),
MYSQLND_METHOD_PRIVATE(mysqlnd_conn, get_state),
MYSQLND_METHOD_PRIVATE(mysqlnd_conn, set_state),
MYSQLND_METHOD(mysqlnd_conn, simple_command),
MYSQLND_METHOD(mysqlnd_conn, simple_command_handle_response)
MYSQLND_CLASS_METHODS_END;
@@ -2323,17 +2101,9 @@ PHPAPI MYSQLND *_mysqlnd_init(zend_bool persistent TSRMLS_DC)
ret->m = mysqlnd_conn_methods;
ret->m->get_reference(ret TSRMLS_CC);
ret->net.stream_read = mysqlnd_read_from_stream;
ret->net.stream_write = mysqlnd_stream_write;
ret->net = mysqlnd_net_init(persistent TSRMLS_CC);
#ifdef MYSQLND_THREADED
ret->LOCK_state = tsrm_mutex_alloc();
pthread_mutex_init(&ret->LOCK_work, NULL);
pthread_cond_init(&ret->COND_work, NULL);
pthread_cond_init(&ret->COND_work_done, NULL);
pthread_cond_init(&ret->COND_thread_ended, NULL);
#endif
CONN_SET_STATE(ret, CONN_ALLOCED);
DBG_RETURN(ret);
}
@@ -2378,7 +2148,7 @@ PHPAPI unsigned int mysqlnd_plugin_register()
/* {{{ mysqlnd_plugin_count */
unsigned int mysqlnd_plugin_count()
PHPAPI unsigned int mysqlnd_plugin_count()
{
return mysqlnd_plugins_counter;
}
@@ -2393,7 +2163,7 @@ PHPAPI void ** _mysqlnd_plugin_get_plugin_connection_data(const MYSQLND * conn,
if (!conn || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)(conn + sizeof(MYSQLND) + plugin_id * sizeof(void *)));
DBG_RETURN((void *)((char *)conn + sizeof(MYSQLND) + plugin_id * sizeof(void *)));
}
/* }}} */
+11 -73
View File
@@ -22,8 +22,8 @@
#ifndef MYSQLND_H
#define MYSQLND_H
#define MYSQLND_VERSION "mysqlnd 5.0.6-dev - 091022 - $Revision$"
#define MYSQLND_VERSION_ID 50006
#define MYSQLND_VERSION "mysqlnd 5.0.7-dev - 091210 - $Revision$"
#define MYSQLND_VERSION_ID 50007
/* This forces inlining of some accessor functions */
#define MYSQLND_USE_OPTIMISATIONS 0
@@ -40,8 +40,8 @@
on production systems, if of course measured performance degradation is not
minimal.
*/
#if PHP_DEBUG
//#define MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND 1
#if A0 && PHP_DEBUG
#define MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND 1
#endif
#if PHP_DEBUG && !defined(PHP_WIN32)
@@ -59,20 +59,21 @@
#include "mysqlnd_structs.h"
/* Library related */
void mysqlnd_library_init(TSRMLS_D);
void mysqlnd_library_end(TSRMLS_D);
PHPAPI unsigned int mysqlnd_plugin_register();
unsigned int mysqlnd_plugin_count();
PHPAPI unsigned int mysqlnd_plugin_count();
PHPAPI void ** _mysqlnd_plugin_get_plugin_connection_data(const MYSQLND * conn, unsigned int plugin_id TSRMLS_DC);
#define mysqlnd_plugin_get_plugin_connection_data(c, p_id) _mysqlnd_plugin_get_plugin_connection_data((c), (p_id) TSRMLS_CC)
PHPAPI void ** _mysqlnd_plugin_get_plugin_result_data(const MYSQLND_RES * result, unsigned int plugin_id TSRMLS_DC);
#define mysqlnd_plugin_get_plugin_result_data(r, p_id) _mysqlnd_plugin_get_plugin_result_data((r), (p_id) TSRMLS_CC)
PHPAPI void ** _mysqlnd_plugin_get_plugin_stmt_data(const MYSQLND_STMT * stmt, unsigned int plugin_id TSRMLS_DC);
#define mysqlnd_plugin_get_plugin_stmt_data(s, p_id) _mysqlnd_plugin_get_plugin_stmt_data((s), (p_id) TSRMLS_CC)
PHPAPI struct st_mysqlnd_conn_methods * mysqlnd_conn_get_methods();
PHPAPI void mysqlnd_conn_set_methods(struct st_mysqlnd_conn_methods *methods);
@@ -81,8 +82,8 @@ PHPAPI struct st_mysqlnd_stmt_methods * mysqlnd_stmt_get_methods();
PHPAPI void mysqlnd_stmt_set_methods(struct st_mysqlnd_stmt_methods *methods);
#define mysqlnd_restart_psession(conn, cache) _mysqlnd_restart_psession((conn), (cache) TSRMLS_CC)
PHPAPI void _mysqlnd_restart_psession(MYSQLND *conn, MYSQLND_THD_ZVAL_PCACHE *cache TSRMLS_DC);
#define mysqlnd_restart_psession(conn) _mysqlnd_restart_psession((conn) TSRMLS_CC)
PHPAPI void _mysqlnd_restart_psession(MYSQLND * conn TSRMLS_DC);
#define mysqlnd_end_psession(conn) _mysqlnd_end_psession((conn) TSRMLS_CC)
PHPAPI void _mysqlnd_end_psession(MYSQLND *conn TSRMLS_DC);
PHPAPI void mysqlnd_minfo_print_hash(zval *values);
@@ -101,8 +102,7 @@ PHPAPI MYSQLND * mysqlnd_connect(MYSQLND *conn,
const char *db, unsigned int db_len,
unsigned int port,
const char *socket,
unsigned int mysql_flags,
MYSQLND_THD_ZVAL_PCACHE *zval_cache
unsigned int mysql_flags
TSRMLS_DC);
#define mysqlnd_change_user(conn, user, passwd, db, silent) (conn)->m->change_user((conn), (user), (passwd), (db), (silent) TSRMLS_CC)
@@ -129,7 +129,6 @@ PHPAPI enum_func_status _mysqlnd_poll(MYSQLND **r_array, MYSQLND **e_array, MYSQ
#define mysqlnd_use_result(conn) (conn)->m->use_result((conn) TSRMLS_CC)
#define mysqlnd_store_result(conn) (conn)->m->store_result((conn) TSRMLS_CC)
#define mysqlnd_bg_store_result(conn) (conn)->m->background_store_result((conn) TSRMLS_CC)
#define mysqlnd_next_result(conn) (conn)->m->next_result((conn) TSRMLS_CC)
#define mysqlnd_more_results(conn) (conn)->m->more_results((conn) TSRMLS_CC)
#define mysqlnd_free_result(r,e_or_i) ((MYSQLND_RES*)r)->m.free_result(((MYSQLND_RES*)(r)), (e_or_i) TSRMLS_CC)
@@ -279,7 +278,6 @@ PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, size
/* PS */
#define mysqlnd_stmt_init(conn) (conn)->m->stmt_init((conn) TSRMLS_CC)
#define mysqlnd_stmt_store_result(stmt) (!mysqlnd_stmt_field_count((stmt)) ? PASS:((stmt)->m->store_result((stmt) TSRMLS_CC)? PASS:FAIL))
#define mysqlnd_stmt_bg_store_result(stmt) (!mysqlnd_stmt_field_count((stmt)) ? PASS:((stmt)->m->background_store_result((stmt) TSRMLS_CC)? PASS:FAIL))
#define mysqlnd_stmt_get_result(stmt) (stmt)->m->get_result((stmt) TSRMLS_CC)
#define mysqlnd_stmt_more_results(stmt) (stmt)->m->more_results((stmt) TSRMLS_CC)
#define mysqlnd_stmt_next_result(stmt) (stmt)->m->next_result((stmt) TSRMLS_CC)
@@ -311,63 +309,6 @@ PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, size
/* Performance statistics */
PHPAPI void _mysqlnd_get_client_stats(zval *return_value TSRMLS_DC ZEND_FILE_LINE_DC);
/* Persistent caching zval allocator */
#define mysqlnd_palloc_init_cache(size) _mysqlnd_palloc_init_cache((size) TSRMLS_CC)
#define mysqlnd_palloc_free_cache(cache) _mysqlnd_palloc_free_cache((cache) TSRMLS_CC)
PHPAPI MYSQLND_ZVAL_PCACHE* _mysqlnd_palloc_init_cache(unsigned int cache_size TSRMLS_DC);
PHPAPI void _mysqlnd_palloc_free_cache(MYSQLND_ZVAL_PCACHE *cache TSRMLS_DC);
PHPAPI void mysqlnd_palloc_stats(const MYSQLND_ZVAL_PCACHE * const cache,
zval *return_value);
#define mysqlnd_palloc_rinit(cache) _mysqlnd_palloc_rinit((cache) TSRMLS_CC)
#define mysqlnd_palloc_rshutdown(cache) _mysqlnd_palloc_rshutdown((cache) TSRMLS_CC)
PHPAPI MYSQLND_THD_ZVAL_PCACHE * _mysqlnd_palloc_rinit(MYSQLND_ZVAL_PCACHE * cache TSRMLS_DC);
PHPAPI void _mysqlnd_palloc_rshutdown(MYSQLND_THD_ZVAL_PCACHE * cache TSRMLS_DC);
#define mysqlnd_palloc_init_thd_cache(cache) _mysqlnd_palloc_init_thd_cache((cache) TSRMLS_CC)
#define mysqlnd_palloc_free_thd_cache_reference(cache) _mysqlnd_palloc_free_thd_cache_reference((cache) TSRMLS_CC)
#define mysqlnd_palloc_get_thd_cache_reference(cache) _mysqlnd_palloc_get_thd_cache_reference((cache) TSRMLS_CC)
PHPAPI MYSQLND_THD_ZVAL_PCACHE* _mysqlnd_palloc_init_thd_cache(MYSQLND_ZVAL_PCACHE * const cache TSRMLS_DC);
MYSQLND_THD_ZVAL_PCACHE* _mysqlnd_palloc_get_thd_cache_reference(MYSQLND_THD_ZVAL_PCACHE * const cache TSRMLS_DC);
PHPAPI void _mysqlnd_palloc_free_thd_cache_reference(MYSQLND_THD_ZVAL_PCACHE **cache TSRMLS_DC);
/* There two should not be used from outside */
void * mysqlnd_palloc_get_zval(MYSQLND_THD_ZVAL_PCACHE * const cache, zend_bool *allocated TSRMLS_DC);
void mysqlnd_palloc_zval_ptr_dtor(zval **zv, MYSQLND_THD_ZVAL_PCACHE * const cache,
enum_mysqlnd_res_type type, zend_bool *copy_ctor_called TSRMLS_DC);
/* ---------------------- QUERY CACHE ---------------*/
struct st_mysqlnd_qcache {
HashTable *ht;
unsigned int references;
#ifdef ZTS
MUTEX_T LOCK_access;
#endif
};
typedef struct st_mysqlnd_qcache_element {
MYSQLND_RES_BUFFERED *data;
MYSQLND_RES_METADATA *meta;
const char * query;
size_t query_len;
} MYSQLND_QCACHE_ELEMENT;
PHPAPI MYSQLND_QCACHE * mysqlnd_qcache_init_cache();
PHPAPI MYSQLND_QCACHE * mysqlnd_qcache_get_cache_reference(MYSQLND_QCACHE * const cache);
PHPAPI void mysqlnd_qcache_free_cache_reference(MYSQLND_QCACHE **cache);
PHPAPI void mysqlnd_qcache_stats(const MYSQLND_QCACHE * const cache, zval *return_value);
MYSQLND_RES * mysqlnd_qcache_get(MYSQLND_QCACHE * const cache, const char * query,
size_t query_len);
void mysqlnd_qcache_put(MYSQLND_QCACHE * const cache, char * query, size_t query_len,
MYSQLND_RES_BUFFERED * const result, MYSQLND_RES_METADATA * const meta);
/* double check the class name to avoid naming conflicts when using these: */
#define MYSQLND_METHOD(class, method) php_##class##_##method##_pub
#define MYSQLND_METHOD_PRIVATE(class, method) php_##class##_##method##_priv
@@ -380,9 +321,6 @@ ZEND_BEGIN_MODULE_GLOBALS(mysqlnd)
long net_cmd_buffer_size;
long net_read_buffer_size;
long log_mask;
#ifdef MYSQLND_THREADED
THREAD_T thread_id;
#endif
long net_read_timeout;
ZEND_END_MODULE_GLOBALS(mysqlnd)
+1 -51
View File
@@ -1,4 +1,4 @@
/*
;/*
+----------------------------------------------------------------------+
| PHP Version 6 |
+----------------------------------------------------------------------+
@@ -25,7 +25,6 @@
#include "mysqlnd_priv.h"
#include "mysqlnd_debug.h"
#include "mysqlnd_wireprotocol.h"
#include "mysqlnd_palloc.h"
#include "mysqlnd_statistics.h"
#include "zend_builtin_functions.h"
@@ -95,12 +94,6 @@ MYSQLND_METHOD(mysqlnd_debug, log)(MYSQLND_DEBUG * self,
line_buffer[6], level_buffer[7];
MYSQLND_ZTS(self);
#ifdef MYSQLND_THREADED
if (MYSQLND_G(thread_id) != tsrm_thread_id()) {
return PASS; /* don't trace background threads */
}
#endif
if (!self->stream) {
if (FAIL == self->m->open(self, FALSE)) {
return FAIL;
@@ -201,12 +194,6 @@ MYSQLND_METHOD(mysqlnd_debug, log_va)(MYSQLND_DEBUG *self,
line_buffer[6], level_buffer[7];
MYSQLND_ZTS(self);
#ifdef MYSQLND_THREADED
if (MYSQLND_G(thread_id) != tsrm_thread_id()) {
return PASS; /* don't trace background threads */
}
#endif
if (!self->stream) {
if (FAIL == self->m->open(self, FALSE)) {
return FAIL;
@@ -303,17 +290,9 @@ MYSQLND_METHOD(mysqlnd_debug, func_enter)(MYSQLND_DEBUG * self,
unsigned int line, const char * const file,
char * func_name, unsigned int func_name_len)
{
#ifdef MYSQLND_THREADED
MYSQLND_ZTS(self);
#endif
if ((self->flags & MYSQLND_DEBUG_DUMP_TRACE) == 0 || self->file_name == NULL) {
return FALSE;
}
#ifdef MYSQLND_THREADED
if (MYSQLND_G(thread_id) != tsrm_thread_id()) {
return FALSE; /* don't trace background threads */
}
#endif
if (zend_stack_count(&self->call_stack) >= self->nest_level_limit) {
return FALSE;
}
@@ -325,7 +304,6 @@ MYSQLND_METHOD(mysqlnd_debug, func_enter)(MYSQLND_DEBUG * self,
func_name == mysqlnd_efree_name || func_name == mysqlnd_pefree_name ||
func_name == mysqlnd_malloc_name || func_name == mysqlnd_calloc_name ||
func_name == mysqlnd_realloc_name || func_name == mysqlnd_free_name ||
func_name == mysqlnd_palloc_zval_ptr_dtor_name || func_name == mysqlnd_palloc_get_zval_name ||
func_name == mysqlnd_read_header_name || func_name == mysqlnd_read_body_name)) {
zend_stack_push(&self->call_stack, "", sizeof(""));
return FALSE;
@@ -351,17 +329,9 @@ MYSQLND_METHOD(mysqlnd_debug, func_leave)(MYSQLND_DEBUG * self, unsigned int lin
const char * const file)
{
char *func_name;
#ifdef MYSQLND_THREADED
MYSQLND_ZTS(self);
#endif
if ((self->flags & MYSQLND_DEBUG_DUMP_TRACE) == 0 || self->file_name == NULL) {
return PASS;
}
#ifdef MYSQLND_THREADED
if (MYSQLND_G(thread_id) != tsrm_thread_id()) {
return PASS; /* don't trace background threads */
}
#endif
if (zend_stack_count(&self->call_stack) >= self->nest_level_limit) {
return PASS;
}
@@ -670,11 +640,6 @@ void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D)
{
void *ret;
DBG_ENTER(mysqlnd_emalloc_name);
#ifdef MYSQLND_THREADED
if (MYSQLND_G(thread_id) != tsrm_thread_id()) {
DBG_RETURN(_mysqlnd_pemalloc(size, 1 TSRMLS_CC ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC));
}
#endif
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
@@ -723,11 +688,6 @@ void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D)
{
void *ret;
DBG_ENTER(mysqlnd_ecalloc_name);
#ifdef MYSQLND_THREADED
if (MYSQLND_G(thread_id) != tsrm_thread_id()) {
DBG_RETURN(_mysqlnd_pecalloc(nmemb, size, 1 TSRMLS_CC ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC));
}
#endif
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
@@ -776,11 +736,6 @@ void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D)
{
void *ret;
DBG_ENTER(mysqlnd_erealloc_name);
#ifdef MYSQLND_THREADED
if (MYSQLND_G(thread_id) != tsrm_thread_id()) {
DBG_RETURN(_mysqlnd_perealloc(ptr, new_size, 1 TSRMLS_CC ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC));
}
#endif
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
DBG_INF_FMT("ptr=%p new_size=%lu", ptr, new_size);
DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
@@ -830,11 +785,6 @@ void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQL
void _mysqlnd_efree(void *ptr MYSQLND_MEM_D)
{
DBG_ENTER(mysqlnd_efree_name);
#ifdef MYSQLND_THREADED
if (MYSQLND_G(thread_id) != tsrm_thread_id()) {
DBG_RETURN(_mysqlnd_pefree(ptr, 1 TSRMLS_CC ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC));
}
#endif
DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
DBG_INF_FMT("ptr=%p", ptr);
DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
+54
View File
@@ -478,6 +478,60 @@ typedef enum mysqlnd_collected_stats
} enum_mysqlnd_collected_stats;
/* Enums */
enum php_mysql_packet_type
{
PROT_GREET_PACKET= 0,
PROT_AUTH_PACKET,
PROT_OK_PACKET,
PROT_EOF_PACKET,
PROT_CMD_PACKET,
PROT_RSET_HEADER_PACKET,
PROT_RSET_FLD_PACKET,
PROT_ROW_PACKET,
PROT_STATS_PACKET,
PROT_PREPARE_RESP_PACKET,
PROT_CHG_USER_PACKET,
PROT_LAST, /* should always be last */
};
enum php_mysqlnd_server_command
{
COM_SLEEP = 0,
COM_QUIT,
COM_INIT_DB,
COM_QUERY,
COM_FIELD_LIST,
COM_CREATE_DB,
COM_DROP_DB,
COM_REFRESH,
COM_SHUTDOWN,
COM_STATISTICS,
COM_PROCESS_INFO,
COM_CONNECT,
COM_PROCESS_KILL,
COM_DEBUG,
COM_PING,
COM_TIME = 15,
COM_DELAYED_INSERT,
COM_CHANGE_USER,
COM_BINLOG_DUMP,
COM_TABLE_DUMP,
COM_CONNECT_OUT = 20,
COM_REGISTER_SLAVE,
COM_STMT_PREPARE = 22,
COM_STMT_EXECUTE = 23,
COM_STMT_SEND_LONG_DATA = 24,
COM_STMT_CLOSE = 25,
COM_STMT_RESET = 26,
COM_SET_OPTION = 27,
COM_STMT_FETCH = 28,
COM_DAEMON,
COM_END
};
#define MYSQLND_DEFAULT_PREFETCH_ROWS (ulong) 1
#define MYSQLND_REFRESH_GRANT 1 /* Refresh grant tables */
+5 -11
View File
@@ -25,12 +25,6 @@
#include "mysqlnd_priv.h"
#include "mysqlnd_debug.h"
enum_func_status mysqlnd_simple_command_handle_response(MYSQLND *conn,
enum php_mysql_packet_type ok_packet,
zend_bool silent, enum php_mysqlnd_server_command command,
zend_bool ignore_upsert_status
TSRMLS_DC);
#define ALLOC_CALLBACK_ARGS(a, b, c)\
if (c) {\
@@ -188,7 +182,7 @@ mysqlnd_handle_local_infile(MYSQLND *conn, const char *filename, zend_bool *is_w
if (!(conn->options.flags & CLIENT_LOCAL_FILES)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "LOAD DATA LOCAL INFILE forbidden");
/* write empty packet to server */
ret = mysqlnd_stream_write_w_header(conn, empty_packet, 0 TSRMLS_CC);
ret = conn->net->m.send(conn, empty_packet, 0 TSRMLS_CC);
*is_warning = TRUE;
goto infile_error;
}
@@ -208,14 +202,14 @@ mysqlnd_handle_local_infile(MYSQLND *conn, const char *filename, zend_bool *is_w
infile.local_infile_error(info, conn->error_info.error,
sizeof(conn->error_info.error) TSRMLS_CC);
/* write empty packet to server */
ret = mysqlnd_stream_write_w_header(conn, empty_packet, 0 TSRMLS_CC);
ret = conn->net->m.send(conn, empty_packet, 0 TSRMLS_CC);
goto infile_error;
}
/* read data */
while ((bufsize = infile.local_infile_read (info, buf + MYSQLND_HEADER_SIZE,
buflen - MYSQLND_HEADER_SIZE TSRMLS_CC)) > 0) {
if ((ret = mysqlnd_stream_write_w_header(conn, buf, bufsize TSRMLS_CC)) < 0) {
if ((ret = conn->net->m.send(conn, buf, bufsize TSRMLS_CC)) < 0) {
DBG_ERR_FMT("Error during read : %d %s %s", CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
goto infile_error;
@@ -223,7 +217,7 @@ mysqlnd_handle_local_infile(MYSQLND *conn, const char *filename, zend_bool *is_w
}
/* send empty packet for eof */
if ((ret = mysqlnd_stream_write_w_header(conn, empty_packet, 0 TSRMLS_CC)) < 0) {
if ((ret = conn->net->m.send(conn, empty_packet, 0 TSRMLS_CC)) < 0) {
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
goto infile_error;
}
@@ -242,7 +236,7 @@ mysqlnd_handle_local_infile(MYSQLND *conn, const char *filename, zend_bool *is_w
infile_error:
/* get response from server and update upsert values */
if (FAIL == mysqlnd_simple_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_QUERY, FALSE TSRMLS_CC)) {
if (FAIL == conn->m->simple_command_handle_response(conn, PROT_OK_PACKET, FALSE, COM_QUERY, FALSE TSRMLS_CC)) {
result = FAIL;
}
+729
View File
@@ -0,0 +1,729 @@
/*
+----------------------------------------------------------------------+
| PHP Version 6 |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Georg Richter <georg@mysql.com> |
| Andrey Hristov <andrey@mysql.com> |
| Ulf Wendel <uwendel@mysql.com> |
+----------------------------------------------------------------------+
*/
#include "php.h"
#include "php_globals.h"
#include "mysqlnd.h"
#include "mysqlnd_priv.h"
#include "mysqlnd_wireprotocol.h"
#include "mysqlnd_statistics.h"
#include "mysqlnd_debug.h"
#include "mysqlnd_block_alloc.h"
#include "ext/standard/sha1.h"
#include "php_network.h"
#include "zend_ini.h"
#ifdef MYSQLND_COMPRESSION_ENABLED
#include <zlib.h>
#endif
#ifndef PHP_WIN32
#include <netinet/tcp.h>
#else
#include <winsock.h>
#endif
/* {{{ mysqlnd_set_sock_no_delay */
static int
mysqlnd_set_sock_no_delay(php_stream * stream)
{
int socketd = ((php_netstream_data_t*)stream->abstract)->socket;
int ret = SUCCESS;
int flag = 1;
int result = setsockopt(socketd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
TSRMLS_FETCH();
DBG_ENTER("mysqlnd_set_sock_no_delay");
if (result == -1) {
ret = FAILURE;
}
DBG_RETURN(ret);
}
/* }}} */
/* {{{ mysqlnd_net::network_read */
static enum_func_status
MYSQLND_METHOD(mysqlnd_net, network_read)(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC)
{
size_t to_read = count, ret;
size_t old_chunk_size = conn->net->stream->chunk_size;
DBG_ENTER("mysqlnd_net::network_read");
DBG_INF_FMT("count=%u", count);
conn->net->stream->chunk_size = MIN(to_read, conn->net->options.net_read_buffer_size);
while (to_read) {
if (!(ret = php_stream_read(conn->net->stream, (char *) buffer, to_read))) {
DBG_ERR_FMT("Error while reading header from socket");
DBG_RETURN(FAIL);
}
buffer += ret;
to_read -= ret;
}
MYSQLND_INC_CONN_STATISTIC_W_VALUE(&conn->stats, STAT_BYTES_RECEIVED, count);
conn->net->stream->chunk_size = old_chunk_size;
DBG_RETURN(PASS);
}
/* }}} */
/* {{{ mysqlnd_net::network_write */
static size_t
MYSQLND_METHOD(mysqlnd_net, network_write)(MYSQLND * const conn, const zend_uchar * const buf, size_t count TSRMLS_DC)
{
size_t ret;
DBG_ENTER("mysqlnd_net::network_write");
ret = php_stream_write(conn->net->stream, (char *)buf, count);
DBG_RETURN(ret);
}
/* }}} */
/* {{{ mysqlnd_net::connect */
static enum_func_status
MYSQLND_METHOD(mysqlnd_net, connect)(MYSQLND_NET * net, const char * const scheme, size_t scheme_len, zend_bool persistent, char **errstr, int * errcode TSRMLS_DC)
{
unsigned int streams_options = ENFORCE_SAFE_MODE;
unsigned int streams_flags = STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT;
char * hashed_details = NULL;
int hashed_details_len = 0;
struct timeval tv;
DBG_ENTER("mysqlnd_net::connect");
if (persistent) {
hashed_details_len = spprintf(&hashed_details, 0, "%p", net);
DBG_INF_FMT("hashed_details=%s", hashed_details);
}
net->packet_no = net->compressed_envelope_packet_no = 0;
if (net->options.timeout_connect) {
tv.tv_sec = net->options.timeout_connect;
tv.tv_usec = 0;
}
net->stream = php_stream_xport_create(scheme, scheme_len, streams_options, streams_flags,
hashed_details, (net->options.timeout_connect) ? &tv : NULL,
NULL /*ctx*/, errstr, errcode);
if (*errstr || !net->stream) {
if (hashed_details) {
efree(hashed_details);
}
*errcode = CR_CONNECTION_ERROR;
DBG_RETURN(FAIL);
}
if (hashed_details) {
/*
If persistent, the streams register it in EG(persistent_list).
This is unwanted. ext/mysql or ext/mysqli are responsible to clean,
whatever they have to.
*/
zend_rsrc_list_entry *le;
if (zend_hash_find(&EG(persistent_list), hashed_details, hashed_details_len + 1,
(void*) &le) == SUCCESS) {
/*
in_free will let streams code skip destructing - big HACK,
but STREAMS suck big time regarding persistent streams.
Just not compatible for extensions that need persistency.
*/
net->stream->in_free = 1;
zend_hash_del(&EG(persistent_list), hashed_details, hashed_details_len + 1);
net->stream->in_free = 0;
}
#if ZEND_DEBUG
/* Shut-up the streams, they don't know what they are doing */
net->stream->__exposed = 1;
#endif
efree(hashed_details);
}
if (!net->options.timeout_read) {
/* should always happen because read_timeout cannot be set via API */
net->options.timeout_read = (unsigned int) MYSQLND_G(net_read_timeout);
}
if (net->options.timeout_read)
{
tv.tv_sec = net->options.timeout_read;
tv.tv_usec = 0;
php_stream_set_option(net->stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &tv);
}
if (!memcmp(scheme, "tcp://", sizeof("tcp://") - 1)) {
/* TCP -> Set TCP_NODELAY */
mysqlnd_set_sock_no_delay(net->stream);
}
{
unsigned int buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/
net->m.set_client_option(net, MYSQLND_OPT_NET_READ_BUFFER_SIZE, (char *)&buf_size TSRMLS_CC);
}
DBG_RETURN(PASS);
}
/* }}} */
/* We assume that MYSQLND_HEADER_SIZE is 4 bytes !! */
#define STORE_HEADER_SIZE(safe_storage, buffer) int4store((safe_storage), (*(uint32_t *)(buffer)))
#define RESTORE_HEADER_SIZE(buffer, safe_storage) STORE_HEADER_SIZE((safe_storage), (buffer))
/* {{{ mysqlnd_net::send */
/*
IMPORTANT : It's expected that buf has place in the beginning for MYSQLND_HEADER_SIZE !!!!
This is done for performance reasons in the caller of this function.
Otherwise we will have to do send two TCP packets, or do new alloc and memcpy.
Neither are quick, thus the clients of this function are obligated to do
what they are asked for.
`count` is actually the length of the payload data. Thus :
count + MYSQLND_HEADER_SIZE = sizeof(buf) (not the pointer but the actual buffer)
*/
size_t
MYSQLND_METHOD(mysqlnd_net, send)(MYSQLND * const conn, char * const buf, size_t count TSRMLS_DC)
{
zend_uchar safe_buf[((MYSQLND_HEADER_SIZE) + (sizeof(zend_uchar)) - 1) / (sizeof(zend_uchar))];
zend_uchar *safe_storage = safe_buf;
MYSQLND_NET *net = conn->net;
size_t old_chunk_size = net->stream->chunk_size;
size_t ret, packets_sent = 1;
size_t left = count;
zend_uchar *p = (zend_uchar *) buf;
zend_uchar * compress_buf = NULL;
size_t to_be_sent;
DBG_ENTER("mysqlnd_net::send");
DBG_INF_FMT("conn=%llu count=%lu compression=%d", conn->thread_id, count, net->compressed);
net->stream->chunk_size = MYSQLND_MAX_PACKET_SIZE;
if (net->compressed == TRUE) {
size_t comp_buf_size = MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE + MIN(left, MYSQLND_MAX_PACKET_SIZE);
DBG_INF_FMT("compress_buf_size=%d", comp_buf_size);
compress_buf = emalloc(comp_buf_size);
}
do {
to_be_sent = MIN(left, MYSQLND_MAX_PACKET_SIZE);
#ifdef MYSQLND_COMPRESSION_ENABLED
if (net->compressed == TRUE) {
/* here we need to compress the data and then write it, first comes the compressed header */
size_t tmp_complen = to_be_sent;
size_t payload_size;
zend_uchar * uncompressed_payload = p; /* should include the header */
STORE_HEADER_SIZE(safe_storage, uncompressed_payload);
int3store(uncompressed_payload, to_be_sent);
int1store(uncompressed_payload + 3, net->packet_no);
if (PASS == net->m.encode((compress_buf + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE), tmp_complen, uncompressed_payload, to_be_sent + MYSQLND_HEADER_SIZE TSRMLS_CC)) {
int3store(compress_buf + MYSQLND_HEADER_SIZE, to_be_sent + MYSQLND_HEADER_SIZE);
payload_size = tmp_complen;
} else {
int3store(compress_buf + MYSQLND_HEADER_SIZE, 0);
memcpy(compress_buf + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE, uncompressed_payload, to_be_sent + MYSQLND_HEADER_SIZE);
payload_size = to_be_sent + MYSQLND_HEADER_SIZE;
}
RESTORE_HEADER_SIZE(uncompressed_payload, safe_storage);
int3store(compress_buf, payload_size);
int1store(compress_buf + 3, net->packet_no);
DBG_INF_FMT("writing %d bytes to the network", payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE);
ret = conn->net->m.network_write(conn, compress_buf, payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE TSRMLS_CC);
net->compressed_envelope_packet_no++;
#if WHEN_WE_NEED_TO_CHECK_WHETHER_COMPRESSION_WORKS_CORRECTLY
if (res == Z_OK) {
size_t decompressed_size = left + MYSQLND_HEADER_SIZE;
zend_uchar * decompressed_data = malloc(decompressed_size);
int error = net->m.decode(decompressed_data, decompressed_size, compress_buf + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE, payload_size);
if (error == Z_OK) {
int i;
DBG_INF("success decompressing");
for (i = 0 ; i < decompressed_size; i++) {
if (i && (i % 30 == 0)) {
printf("\n\t\t");
}
printf("%.2X ", (int)*((char*)&(decompressed_data[i])));
DBG_INF_FMT("%.2X ", (int)*((char*)&(decompressed_data[i])));
}
} else {
DBG_INF("error decompressing");
}
free(decompressed_data);
}
#endif /* WHEN_WE_NEED_TO_CHECK_WHETHER_COMPRESSION_WORKS_CORRECTLY */
} else
#endif /* MYSQLND_COMPRESSION_ENABLED */
{
DBG_INF("no compression");
STORE_HEADER_SIZE(safe_storage, p);
int3store(p, to_be_sent);
int1store(p + 3, net->packet_no);
ret = conn->net->m.network_write(conn, p, to_be_sent + MYSQLND_HEADER_SIZE TSRMLS_CC);
RESTORE_HEADER_SIZE(p, safe_storage);
net->compressed_envelope_packet_no++;
}
net->packet_no++;
p += to_be_sent;
left -= to_be_sent;
packets_sent++;
/*
if left is 0 then there is nothing more to send, but if the last packet was exactly
with the size MYSQLND_MAX_PACKET_SIZE we need to send additional packet, which has
empty payload. Thus if left == 0 we check for to_be_sent being the max size. If it is
indeed it then loop once more, then to_be_sent will become 0, left will stay 0. Empty
packet will be sent and this loop will end.
*/
} while (ret && (left > 0 || to_be_sent == MYSQLND_MAX_PACKET_SIZE));
DBG_INF_FMT("packet_size=%d packet_no=%d", left, net->packet_no);
/* Even for zero size payload we have to send a packet */
if (!ret) {
DBG_ERR_FMT("Can't %u send bytes", count);
conn->state = CONN_QUIT_SENT;
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
}
MYSQLND_INC_CONN_STATISTIC_W_VALUE3(&conn->stats,
STAT_BYTES_SENT, count + packets_sent * MYSQLND_HEADER_SIZE,
STAT_PROTOCOL_OVERHEAD_OUT, packets_sent * MYSQLND_HEADER_SIZE,
STAT_PACKETS_SENT, packets_sent);
net->stream->chunk_size = old_chunk_size;
if (compress_buf) {
efree(compress_buf);
}
DBG_RETURN(ret);
}
/* }}} */
#ifdef MYSQLND_COMPRESSION_ENABLED
/* {{{ php_mysqlnd_read_buffer_is_empty */
static zend_bool
php_mysqlnd_read_buffer_is_empty(MYSQLND_READ_BUFFER * buffer)
{
return buffer->len? FALSE:TRUE;
}
/* }}} */
/* {{{ php_mysqlnd_read_buffer_read */
static void
php_mysqlnd_read_buffer_read(MYSQLND_READ_BUFFER * buffer, size_t count, zend_uchar * dest)
{
if (buffer->len >= count) {
memcpy(dest, buffer->data + buffer->offset, count);
buffer->offset += count;
buffer->len -= count;
}
}
/* }}} */
/* {{{ php_mysqlnd_read_buffer_bytes_left */
static size_t
php_mysqlnd_read_buffer_bytes_left(MYSQLND_READ_BUFFER * buffer)
{
return buffer->len;
}
/* }}} */
/* {{{ php_mysqlnd_read_buffer_free */
static void
php_mysqlnd_read_buffer_free(MYSQLND_READ_BUFFER ** buffer TSRMLS_DC)
{
DBG_ENTER("php_mysqlnd_read_buffer_free");
if (*buffer) {
mnd_efree((*buffer)->data);
mnd_efree(*buffer);
*buffer = NULL;
}
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ php_mysqlnd_create_read_buffer */
static MYSQLND_READ_BUFFER *
mysqlnd_create_read_buffer(size_t count TSRMLS_DC)
{
MYSQLND_READ_BUFFER * ret = mnd_emalloc(sizeof(MYSQLND_READ_BUFFER));
DBG_ENTER("mysqlnd_create_read_buffer");
ret->is_empty = php_mysqlnd_read_buffer_is_empty;
ret->read = php_mysqlnd_read_buffer_read;
ret->bytes_left = php_mysqlnd_read_buffer_bytes_left;
ret->free_buffer = php_mysqlnd_read_buffer_free;
ret->data = mnd_emalloc(count);
ret->size = ret->len = count;
ret->offset = 0;
DBG_RETURN(ret);
}
/* }}} */
/* {{{ mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer */
static enum_func_status
mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer(MYSQLND * conn, size_t net_payload_size TSRMLS_DC)
{
MYSQLND_NET * net = conn->net;
size_t decompressed_size;
enum_func_status ret = PASS;
zend_uchar * compressed_data = NULL;
zend_uchar comp_header[COMPRESSED_HEADER_SIZE];
DBG_ENTER("mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer");
/* Read the compressed header */
if (FAIL == conn->net->m.network_read(conn, comp_header, COMPRESSED_HEADER_SIZE TSRMLS_CC)) {
DBG_RETURN(FAIL);
}
decompressed_size = uint3korr(comp_header);
/* When decompressed_size is 0, then the data is not compressed, and we have wasted 3 bytes */
/* we need to decompress the data */
if (decompressed_size) {
compressed_data = emalloc(net_payload_size);
if (FAIL == conn->net->m.network_read(conn, compressed_data, net_payload_size TSRMLS_CC)) {
ret = FAIL;
goto end;
}
net->uncompressed_data = mysqlnd_create_read_buffer(decompressed_size TSRMLS_CC);
ret = net->m.decode(net->uncompressed_data->data, decompressed_size, compressed_data, net_payload_size TSRMLS_CC);
if (ret == FAIL) {
goto end;
}
} else {
DBG_INF_FMT("The server decided not to compress the data. Our job is easy. Copying %u bytes", net_payload_size);
net->uncompressed_data = mysqlnd_create_read_buffer(net_payload_size TSRMLS_CC);
if (FAIL == conn->net->m.network_read(conn, net->uncompressed_data->data, net_payload_size TSRMLS_CC)) {
ret = FAIL;
goto end;
}
}
end:
if (compressed_data) {
efree(compressed_data);
}
DBG_RETURN(ret);
}
/* }}} */
#endif /* MYSQLND_COMPRESSION_ENABLED */
/* {{{ mysqlnd_net::decode */
static enum_func_status
MYSQLND_METHOD(mysqlnd_net, decode)(zend_uchar * uncompressed_data, size_t uncompressed_data_len,
const zend_uchar * const compressed_data, size_t compressed_data_len TSRMLS_DC)
{
int error;
uLongf tmp_complen = uncompressed_data_len;
DBG_ENTER("mysqlnd_net::decode");
error = uncompress(uncompressed_data, &tmp_complen, compressed_data, compressed_data_len);
DBG_INF_FMT("compressed data: decomp_len=%d compressed_size=%d", tmp_complen, compressed_data_len);
if (error != Z_OK) {
DBG_INF_FMT("decompression NOT successful. error=%d Z_OK=%d Z_BUF_ERROR=%d Z_MEM_ERROR=%d", error, Z_OK, Z_BUF_ERROR, Z_MEM_ERROR);
}
DBG_RETURN(error == Z_OK? PASS:FAIL);
}
/* }}} */
/* {{{ mysqlnd_net::encode */
static enum_func_status
MYSQLND_METHOD(mysqlnd_net, encode)(zend_uchar * compress_buffer, size_t compress_buffer_len,
const zend_uchar * const uncompressed_data, size_t uncompressed_data_len TSRMLS_DC)
{
int error;
uLongf tmp_complen = compress_buffer_len;
DBG_ENTER("mysqlnd_net::encode");
error = compress(compress_buffer, &tmp_complen, uncompressed_data, uncompressed_data_len);
if (error != Z_OK) {
DBG_INF_FMT("compression NOT successful. error=%d Z_OK=%d Z_BUF_ERROR=%d Z_MEM_ERROR=%d", error, Z_OK, Z_BUF_ERROR, Z_MEM_ERROR);
} else {
DBG_INF_FMT("compression successful. compressed size=%d", tmp_complen);
}
DBG_RETURN(error == Z_OK? PASS:FAIL);
}
/* }}} */
/* {{{ mysqlnd_net::receive */
static enum_func_status
MYSQLND_METHOD(mysqlnd_net, receive)(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC)
{
size_t to_read = count;
zend_uchar * p = buffer;
MYSQLND_NET * net = conn->net;
DBG_ENTER("mysqlnd_net::receive");
#ifdef MYSQLND_COMPRESSION_ENABLED
if (net->compressed) {
if (net->uncompressed_data) {
size_t to_read_from_buffer = MIN(net->uncompressed_data->bytes_left(net->uncompressed_data), to_read);
DBG_INF_FMT("reading %u from uncompressed_data buffer", to_read_from_buffer);
if (to_read_from_buffer) {
net->uncompressed_data->read(net->uncompressed_data, to_read_from_buffer, (zend_uchar *) p);
p += to_read_from_buffer;
to_read -= to_read_from_buffer;
}
DBG_INF_FMT("left %u to read", to_read);
if (TRUE == net->uncompressed_data->is_empty(net->uncompressed_data)) {
/* Everything was consumed. This should never happen here, but for security */
net->uncompressed_data->free_buffer(&net->uncompressed_data TSRMLS_CC);
}
}
if (to_read) {
zend_uchar net_header[MYSQLND_HEADER_SIZE];
size_t net_payload_size;
zend_uchar packet_no;
if (FAIL == net->m.network_read(conn, net_header, MYSQLND_HEADER_SIZE TSRMLS_CC)) {
DBG_RETURN(FAIL);
}
net_payload_size = uint3korr(net_header);
packet_no = uint1korr(net_header + 3);
if (net->compressed_envelope_packet_no != packet_no) {
DBG_ERR_FMT("Transport level: packets out of order. Expected %d received %d. Packet size=%d",
net->compressed_envelope_packet_no, packet_no, net_payload_size);
php_error(E_WARNING, "Packets out of order. Expected %d received %d. Packet size="MYSQLND_SZ_T_SPEC,
net->compressed_envelope_packet_no, packet_no, net_payload_size);
DBG_RETURN(FAIL);
}
net->compressed_envelope_packet_no++;
#ifdef MYSQLND_DUMP_HEADER_N_BODY
DBG_INF_FMT("HEADER: hwd_packet_no=%d size=%3d", packet_no, net_payload_size);
#endif
/* Now let's read from the wire, decompress it and fill the read buffer */
mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer(conn, net_payload_size TSRMLS_CC);
/*
Now a bit of recursion - read from the read buffer,
if the data which we have just read from the wire
is not enough, then the recursive call will try to
satisfy it until it is satisfied.
*/
DBG_RETURN(net->m.receive(conn, p, to_read TSRMLS_CC));
}
DBG_RETURN(PASS);
}
#endif /* MYSQLND_COMPRESSION_ENABLED */
DBG_RETURN(net->m.network_read(conn, p, to_read TSRMLS_CC));
}
/* }}} */
/* {{{ mysqlnd_net::set_client_option */
static enum_func_status
MYSQLND_METHOD(mysqlnd_net, set_client_option)(MYSQLND_NET * const net, enum mysqlnd_option option, const char * const value TSRMLS_DC)
{
DBG_ENTER("mysqlnd_net::set_client_option");
DBG_INF_FMT("option=%d", option);
switch (option) {
case MYSQLND_OPT_NET_CMD_BUFFER_SIZE:
DBG_INF("MYSQLND_OPT_NET_CMD_BUFFER_SIZE");
if (*(unsigned int*) value < MYSQLND_NET_CMD_BUFFER_MIN_SIZE) {
DBG_RETURN(FAIL);
}
net->cmd_buffer.length = *(unsigned int*) value;
DBG_INF_FMT("new_length=%u", net->cmd_buffer.length);
if (!net->cmd_buffer.buffer) {
net->cmd_buffer.buffer = mnd_pemalloc(net->cmd_buffer.length, net->persistent);
} else {
net->cmd_buffer.buffer = mnd_perealloc(net->cmd_buffer.buffer, net->cmd_buffer.length, net->persistent);
}
break;
case MYSQLND_OPT_NET_READ_BUFFER_SIZE:
DBG_INF("MYSQLND_OPT_NET_READ_BUFFER_SIZE");
net->options.net_read_buffer_size = *(unsigned int*) value;
DBG_INF_FMT("new_length=%u", net->options.net_read_buffer_size);
break;
case MYSQL_OPT_CONNECT_TIMEOUT:
DBG_INF("MYSQL_OPT_CONNECT_TIMEOUT");
net->options.timeout_connect = *(unsigned int*) value;
break;
#ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_OPT_READ_TIMEOUT:
DBG_INF("MYSQL_OPT_READ_TIMEOUT");
net->options.timeout_read = *(unsigned int*) value;
break;
case MYSQL_OPT_WRITE_TIMEOUT:
DBG_INF("MYSQL_OPT_WRITE_TIMEOUT");
net->options.timeout_write = *(unsigned int*) value;
break;
#endif
#ifdef WHEN_SUPPORTED_BY_MYSQLI
case MYSQL_OPT_COMPRESS:
#endif
/* currently not supported. Todo!! */
break;
default:
DBG_RETURN(FAIL);
}
DBG_RETURN(PASS);
}
/* }}} */
/* {{{ mysqlnd_net::consume_uneaten_data */
size_t
MYSQLND_METHOD(mysqlnd_net, consume_uneaten_data)(MYSQLND_NET * const net, enum php_mysqlnd_server_command cmd TSRMLS_DC)
{
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
/*
Switch to non-blocking mode and try to consume something from
the line, if possible, then continue. This saves us from looking for
the actuall place where out-of-order packets have been sent.
If someone is completely sure that everything is fine, he can switch it
off.
*/
char tmp_buf[256];
size_t skipped_bytes = 0;
int opt = PHP_STREAM_OPTION_BLOCKING;
int was_blocked = net->stream->ops->set_option(net->stream, opt, 0, NULL TSRMLS_CC);
DBG_ENTER("mysqlnd_net::consume_uneaten_data");
if (PHP_STREAM_OPTION_RETURN_ERR != was_blocked) {
/* Do a read of 1 byte */
int bytes_consumed;
do {
skipped_bytes += (bytes_consumed = php_stream_read(net->stream, tmp_buf, sizeof(tmp_buf)));
} while (bytes_consumed == sizeof(tmp_buf));
if (was_blocked) {
net->stream->ops->set_option(net->stream, opt, 1, NULL TSRMLS_CC);
}
if (bytes_consumed) {
DBG_ERR_FMT("Skipped %u bytes. Last command %s hasn't consumed all the output from the server",
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Skipped %u bytes. Last command %s hasn't "
"consumed all the output from the server",
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
}
}
net->last_command = cmd;
DBG_RETURN(skipped_bytes);
#else
return 0;
#endif
}
/* }}} */
/* {{{ mysqlnd_net::set_client_option */
static void
MYSQLND_METHOD(mysqlnd_net, free_contents)(MYSQLND_NET * net TSRMLS_DC)
{
DBG_ENTER("mysqlnd_net::free_contents");
#ifdef MYSQLND_COMPRESSION_ENABLED
if (net->uncompressed_data) {
net->uncompressed_data->free_buffer(&net->uncompressed_data TSRMLS_CC);
}
#endif
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ mysqlnd_net_init */
MYSQLND_NET *
mysqlnd_net_init(zend_bool persistent TSRMLS_DC)
{
MYSQLND_NET * net = mnd_pecalloc(1, sizeof(MYSQLND_NET), persistent);
DBG_ENTER("mysqlnd_net_init");
DBG_INF_FMT("persistent=%d", persistent);
net->persistent = persistent;
net->m.connect = MYSQLND_METHOD(mysqlnd_net, connect);
net->m.send = MYSQLND_METHOD(mysqlnd_net, send);
net->m.receive = MYSQLND_METHOD(mysqlnd_net, receive);
net->m.set_client_option = MYSQLND_METHOD(mysqlnd_net, set_client_option);
net->m.network_read = MYSQLND_METHOD(mysqlnd_net, network_read);
net->m.network_write = MYSQLND_METHOD(mysqlnd_net, network_write);
net->m.decode = MYSQLND_METHOD(mysqlnd_net, decode);
net->m.encode = MYSQLND_METHOD(mysqlnd_net, encode);
net->m.consume_uneaten_data = MYSQLND_METHOD(mysqlnd_net, consume_uneaten_data);
net->m.free_contents = MYSQLND_METHOD(mysqlnd_net, free_contents);
{
unsigned int buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/
net->m.set_client_option(net, MYSQLND_OPT_NET_CMD_BUFFER_SIZE, (char *) &buf_size TSRMLS_CC);
}
DBG_RETURN(net);
}
/* }}} */
/* {{{ mysqlnd_net_init */
void
mysqlnd_net_free(MYSQLND_NET * net TSRMLS_DC)
{
zend_bool pers = net->persistent;
DBG_ENTER("mysqlnd_net_free");
if (net) {
net->m.free_contents(net TSRMLS_CC);
if (net->cmd_buffer.buffer) {
DBG_INF("Freeing cmd buffer");
mnd_pefree(net->cmd_buffer.buffer, pers);
net->cmd_buffer.buffer = NULL;
}
if (net->stream) {
DBG_INF_FMT("Freeing stream. abstract=%p", net->stream->abstract);
if (pers) {
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR);
} else {
php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE);
}
net->stream = NULL;
}
mnd_pefree(net, pers);
}
DBG_VOID_RETURN;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
+38
View File
@@ -0,0 +1,38 @@
/*
+----------------------------------------------------------------------+
| PHP Version 6 |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Georg Richter <georg@mysql.com> |
| Andrey Hristov <andrey@mysql.com> |
| Ulf Wendel <uwendel@mysql.com> |
+----------------------------------------------------------------------+
*/
/* $Id: mysqlnd_wireprotocol.h 291983 2009-12-11 11:58:57Z andrey $ */
#ifndef MYSQLND_NET_H
#define MYSQLND_NET_H
MYSQLND_NET * mysqlnd_net_init(zend_bool persistent TSRMLS_DC);
void mysqlnd_net_free(MYSQLND_NET * net TSRMLS_DC);
#endif /* MYSQLND_NET_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
-605
View File
@@ -1,605 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP Version 6 |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Georg Richter <georg@mysql.com> |
| Andrey Hristov <andrey@mysql.com> |
| Ulf Wendel <uwendel@mysql.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include "php.h"
#include "mysqlnd.h"
#include "mysqlnd_priv.h"
#include "mysqlnd_palloc.h"
#include "mysqlnd_debug.h"
/* Used in mysqlnd_debug.c */
char * mysqlnd_palloc_zval_ptr_dtor_name = "mysqlnd_palloc_zval_ptr_dtor";
char * mysqlnd_palloc_get_zval_name = "mysqlnd_palloc_get_zval";
#ifdef ZTS
#define LOCK_PCACHE(cache) tsrm_mutex_lock((cache)->LOCK_access)
#define UNLOCK_PCACHE(cache) tsrm_mutex_unlock((cache)->LOCK_access)
#else
#define LOCK_PCACHE(cache)
#define UNLOCK_PCACHE(cache)
#endif
/* {{{ _mysqlnd_palloc_init_cache */
PHPAPI MYSQLND_ZVAL_PCACHE* _mysqlnd_palloc_init_cache(unsigned int cache_size TSRMLS_DC)
{
MYSQLND_ZVAL_PCACHE *ret = mnd_calloc(1, sizeof(MYSQLND_ZVAL_PCACHE));
unsigned int i;
DBG_ENTER("_mysqlnd_palloc_init_cache");
DBG_INF_FMT("cache=%p size=%u", ret, cache_size);
#ifdef ZTS
ret->LOCK_access = tsrm_mutex_alloc();
#endif
ret->max_items = cache_size;
ret->free_items = cache_size;
ret->references = 1;
/* 1. First initialize the free list part of the structure */
/* One more for empty position of last_added - always 0x0, bounds checking */
ret->free_list.ptr_line = mnd_calloc(ret->max_items + 1, sizeof(mysqlnd_zval *));
ret->free_list.last_added = ret->free_list.ptr_line + ret->max_items;
ret->free_list.canary1 = (void*)0xBEEF;
ret->free_list.canary2 = (void*)0xAFFE;
/* 3. Allocate and initialize our zvals and initialize the free list */
ret->block = mnd_calloc(ret->max_items, sizeof(mysqlnd_zval));
ret->last_in_block = &(ret->block[ret->max_items]);
for (i = 0; i < ret->max_items; i++) {
/* 1. Initialize */
INIT_PZVAL(&(ret->block[i].zv));
ZVAL_NULL(&(ret->block[i].zv));
/* Assure it will never be freed before MSHUTDOWN */
Z_ADDREF_P(&(ret->block[i].zv));
/* 2. Add to the free list */
*(--ret->free_list.last_added) = &(ret->block[i]);
}
DBG_RETURN(ret);
}
/* }}} */
/* {{{ mysqlnd_palloc_get_cache_reference */
MYSQLND_ZVAL_PCACHE* mysqlnd_palloc_get_cache_reference(MYSQLND_ZVAL_PCACHE * const cache)
{
if (cache) {
LOCK_PCACHE(cache);
cache->references++;
UNLOCK_PCACHE(cache);
}
return cache;
}
/* }}} */
/* {{{ mysqlnd_palloc_free_cache */
/*
As this call will happen on MSHUTDOWN(), then we don't need to copy the zvals with
copy_ctor but scrap what they point to with zval_dtor() and then just free our
pre-allocated block. Precondition is that we ZVAL_NULL() the zvals when we put them
to the free list after usage. We ZVAL_NULL() them when we allocate them in the
constructor of the cache.
*/
void _mysqlnd_palloc_free_cache(MYSQLND_ZVAL_PCACHE *cache TSRMLS_DC)
{
DBG_ENTER("_mysqlnd_palloc_free_cache");
DBG_INF_FMT("cache=%p", cache);
#ifdef ZTS
tsrm_mutex_free(cache->LOCK_access);
#endif
/* Data in pointed by 'block' was cleaned in RSHUTDOWN */
mnd_free(cache->block);
mnd_free(cache->free_list.ptr_line);
mnd_free(cache);
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ _mysqlnd_palloc_init_thd_cache */
PHPAPI MYSQLND_THD_ZVAL_PCACHE* _mysqlnd_palloc_init_thd_cache(MYSQLND_ZVAL_PCACHE * const cache TSRMLS_DC)
{
MYSQLND_THD_ZVAL_PCACHE *ret = mnd_calloc(1, sizeof(MYSQLND_THD_ZVAL_PCACHE));
DBG_ENTER("_mysqlnd_palloc_init_thd_cache");
DBG_INF_FMT("ret = %p", ret);
#if PHP_DEBUG
LOCK_PCACHE(cache);
if (cache->references == 1 && cache->max_items != cache->free_items) {
UNLOCK_PCACHE(cache);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No references to mysqlnd's zval cache but max_items != free_items");
} else {
UNLOCK_PCACHE(cache);
}
#endif
ret->parent = mysqlnd_palloc_get_cache_reference(cache);
#ifdef ZTS
ret->thread_id = tsrm_thread_id();
#endif
ret->references = 1;
/* 1. Initialize the GC list */
ret->gc_list.ptr_line = mnd_calloc(cache->max_items, sizeof(mysqlnd_zval *));
/* Backward and forward looping is possible */
ret->gc_list.last_added = ret->gc_list.ptr_line;
ret->gc_list.canary1 = (void*)0xCAFE;
ret->gc_list.canary2 = (void*)0x190280;
DBG_INF_FMT("ptr_line=%p last_added=%p", ret->gc_list.ptr_line, ret->gc_list.last_added);
DBG_RETURN(ret);
}
/* }}} */
/* {{{ _mysqlnd_palloc_get_thd_cache_reference */
MYSQLND_THD_ZVAL_PCACHE* _mysqlnd_palloc_get_thd_cache_reference(MYSQLND_THD_ZVAL_PCACHE * const cache TSRMLS_DC)
{
DBG_ENTER("_mysqlnd_palloc_get_thd_cache_reference");
if (cache) {
++cache->references;
DBG_INF_FMT("cache=%p new_refc=%d gc_list.canary1=%p gc_list.canary2=%p",
cache, cache->references, cache->gc_list.canary1, cache->gc_list.canary2);
mysqlnd_palloc_get_cache_reference(cache->parent);
}
DBG_RETURN(cache);
}
/* }}} */
/* {{{ mysqlnd_palloc_free_cache */
/*
As this call will happen on MSHUTDOWN(), then we don't need to copy the zvals with
copy_ctor but scrap what they point to with zval_dtor() and then just free our
pre-allocated block. Precondition is that we ZVAL_NULL() the zvals when we put them
to the free list after usage. We ZVAL_NULL() them when we allocate them in the
constructor of the cache.
*/
static
void mysqlnd_palloc_free_thd_cache(MYSQLND_THD_ZVAL_PCACHE *thd_cache TSRMLS_DC)
{
MYSQLND_ZVAL_PCACHE *global_cache;
mysqlnd_zval **p;
DBG_ENTER("mysqlnd_palloc_free_thd_cache");
DBG_INF_FMT("thd_cache=%p", thd_cache);
if ((global_cache = thd_cache->parent)) {
/*
Keep in mind that for pthreads pthread_equal() should be used to be
fully standard compliant. However, the PHP code all-around, incl. the
the Zend MM uses direct comparison.
*/
p = thd_cache->gc_list.ptr_line;
while (p < thd_cache->gc_list.last_added) {
zval_dtor(&(*p)->zv);
p++;
}
p = thd_cache->gc_list.ptr_line;
LOCK_PCACHE(global_cache);
while (p < thd_cache->gc_list.last_added) {
(*p)->point_type = MYSQLND_POINTS_FREE;
*(--global_cache->free_list.last_added) = *p;
++global_cache->free_items;
#ifdef ZTS
memset(&((*p)->thread_id), 0, sizeof(THREAD_T));
#endif
p++;
}
UNLOCK_PCACHE(global_cache);
}
mnd_free(thd_cache->gc_list.ptr_line);
mnd_free(thd_cache);
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ _mysqlnd_palloc_free_thd_cache_reference */
PHPAPI void _mysqlnd_palloc_free_thd_cache_reference(MYSQLND_THD_ZVAL_PCACHE **cache TSRMLS_DC)
{
DBG_ENTER("_mysqlnd_palloc_free_thd_cache_reference");
if (*cache) {
--(*cache)->parent->references;
DBG_INF_FMT("cache=%p references_left=%d canary1=%p canary2=%p",
*cache, (*cache)->references, (*cache)->gc_list.canary1, (*cache)->gc_list.canary2);
DBG_INF_FMT("gc_list.ptr_line=%p gc_list.last_added=%p", (*cache)->gc_list.ptr_line, (*cache)->gc_list.last_added);
if (--(*cache)->references == 0) {
mysqlnd_palloc_free_thd_cache(*cache TSRMLS_CC);
}
*cache = NULL;
}
DBG_VOID_RETURN;
}
/* }}} */
/*
The cache line is a big contiguous array of zval pointers.
Because the CPU cache will cache starting from an address, and not
before it, then we have to organize our structure according to this.
Thus, if 'last_added' is valid pointer (not NULL) then last_added is
increased. When zval is cached, if there is room, last_added is decreased
and then the zval pointer will be assigned to it. This means that some
positions may become hot points and stay in the cache.
Imagine we have 5 pointers in a line
1. last_added = list_item->ptr_line + cache->max_items;
2. get_zval -> *last_added = NULL. Use MAKE_STD_ZVAL
3. get_zval -> *last_added = NULL. Use MAKE_STD_ZVAL
4. get_zval -> *last_added = NULL. Use MAKE_STD_ZVAL
0x0
0x0
0x0
0x0
0x0
---
empty_position, always 0x0 <-- last_added
5. free_zval -> if (free_items++ != max_items) {// we can add more
*(--last_added) = zval_ptr;
}
(memory addresses increase downwards)
0x0
0x0
0x0
0x0
0xA <-- last_added
---
0x0
6. free_zval -> if (free_items++ != max_items) {// we can add more
*(--last_added) = zval_ptr;
}
0x0
0x0
0x0
0xB <-- last_added
0xA
---
0x0
7. free_zval -> if (free_items++ != max_items) {// we can add more
*(--last_added) = zval_ptr;
}
0x0
0x0
0xC <-- last_added
0xB
0xA
---
0x0
8. get_zval -> *last_added != NULL. -> p = *last_added; *last_added++ = NULL;
0x0
0x0
0x0
0xB <-- last_added
0xA
---
0x0
9. get_zval -> *last_added != NULL. -> p = *last_added; *last_added++ = NULL;
0x0
0x0
0x0
0x0
0xA <-- last_added
---
0x0
10. get_zval -> *last_added != NULL. -> p = *last_added; *last_added++ = NULL;
0x0
0x0
0x0
0x0
0x0
---
0x0 <-- last_added
*/
/* {{{ mysqlnd_palloc_get_zval */
void *mysqlnd_palloc_get_zval(MYSQLND_THD_ZVAL_PCACHE * const thd_cache, zend_bool *allocated TSRMLS_DC)
{
void *ret = NULL;
DBG_ENTER("mysqlnd_palloc_get_zval");
if (thd_cache) {
DBG_INF_FMT("cache=%p *last_added=%p free_items=%d",
thd_cache, thd_cache->parent->free_list.last_added,
thd_cache->parent->free_items);
DBG_INF_FMT("gc_list.ptr_line=%p gc_list.last_added=%p gc_list.canary1=%p gc_list.canary2=%p",
thd_cache->gc_list.ptr_line, thd_cache->gc_list.last_added,
thd_cache->gc_list.canary1, thd_cache->gc_list.canary2);
}
if (thd_cache) {
MYSQLND_ZVAL_PCACHE *cache = thd_cache->parent;
LOCK_PCACHE(cache);
DBG_INF_FMT("free_items=%d free_list.ptr_line=%p free_list.last_added=%p *free_list.last_added=%p free_list.canary1=%p free_list.canary2=%p",
cache->free_items, cache->free_list.ptr_line, cache->free_list.last_added,
*cache->free_list.last_added,
cache->free_list.canary1, cache->free_list.canary2);
/* We have max_items + 1 allocated block for free_list, thus we know if we */
if ((ret = *cache->free_list.last_added)) {
*cache->free_list.last_added++ = NULL;
*allocated = FALSE;
#ifdef ZTS
((mysqlnd_zval *) ret)->thread_id = thd_cache->thread_id;
#endif
--cache->free_items;
++cache->get_hits;
} else {
++cache->get_misses;
}
UNLOCK_PCACHE(cache);
}
if (!ret) {
/*
We allocate a bit more. The user of this function will use it, but at
end it will use only the zval part. Because the zval part is first then
when freeing the zval part the whole allocated block will be cleaned, not
only the zval part (by the Engine when destructing the zval).
*/
ALLOC_ZVAL(ret);
INIT_PZVAL((zval *) ret);
*allocated = TRUE;
} else {
/* This will set the refcount to 1, increase it, to keep the variable */
INIT_PZVAL(&((mysqlnd_zval *) ret)->zv);
Z_ADDREF_P(&(((mysqlnd_zval *)ret)->zv));
}
DBG_INF_FMT("allocated=%d ret=%p", *allocated, ret);
DBG_RETURN(ret);
}
/* }}} */
/* {{{ mysqlnd_palloc_zval_ptr_dtor */
void mysqlnd_palloc_zval_ptr_dtor(zval **zv, MYSQLND_THD_ZVAL_PCACHE * const thd_cache,
enum_mysqlnd_res_type type, zend_bool *copy_ctor_called TSRMLS_DC)
{
MYSQLND_ZVAL_PCACHE *cache;
DBG_ENTER("mysqlnd_palloc_zval_ptr_dtor");
if (thd_cache) {
DBG_INF_FMT("cache=%p parent_block=%p last_in_block=%p *zv=%p refc=%d type=%d ",
thd_cache,
thd_cache->parent->block,
thd_cache->parent->last_in_block,
*zv, Z_REFCOUNT_PP(zv), type);
DBG_INF_FMT("gc_list.ptr_line=%p gc_list.last_added=%p gc_list.canary1=%p gc_list.canary2=%p",
thd_cache->gc_list.ptr_line, thd_cache->gc_list.last_added, thd_cache->gc_list.canary1, thd_cache->gc_list.canary2);
}
*copy_ctor_called = FALSE;
/* Check whether cache is used and the zval is from the cache */
if (!thd_cache || !(cache = thd_cache->parent) || ((char *)*zv < (char *)thd_cache->parent->block ||
(char *)*zv > (char *)thd_cache->parent->last_in_block)) {
/*
This zval is not from the cache block.
Thus the refcount is -1 than of a zval from the cache,
because the zvals from the cache are owned by it.
*/
if (type == MYSQLND_RES_PS_BUF || type == MYSQLND_RES_PS_UNBUF) {
; /* do nothing, zval_ptr_dtor will do the job*/
} else if (Z_REFCOUNT_PP(zv) > 1) {
/*
Not a prepared statement, then we have to
call copy_ctor and then zval_ptr_dtor()
In Unicode mode the destruction of the zvals should not call
zval_copy_ctor() because then we will leak.
I suppose we can use UG(unicode) in mysqlnd.c when freeing a result set
to check if we need to call copy_ctor().
If the type is IS_UNICODE, which can happen with PHP6, then we don't
need to copy_ctor, as the data doesn't point to our internal buffers.
If it's string (in PHP5 always) and in PHP6 if data is binary, then
it still points to internal buffers and has to be copied.
*/
if (Z_TYPE_PP(zv) == IS_STRING) {
zval_copy_ctor(*zv);
}
*copy_ctor_called = TRUE;
} else {
if (Z_TYPE_PP(zv) == IS_STRING) {
ZVAL_NULL(*zv);
}
}
zval_ptr_dtor(zv);
DBG_VOID_RETURN;
}
/* The zval is from our cache */
/* refcount is always > 1, because we call Z_ADDREF_P(). Thus test refcount > 2 */
if (Z_REFCOUNT_PP(zv) > 2) {
/*
Because the zval is first element in mysqlnd_zval structure, then we can
do upcasting from zval to mysqlnd_zval here. Because we know that this
zval is part of our pre-allocated block.
Now check whether this zval points to ZE allocated memory or to our
buffers. If it points to the internal buffers, call copy_ctor()
which will do estrndup for strings. And nothing for null, int, double.
This branch will be skipped for PS, because there is no need to copy
what is pointed by them, as they don't point to the internal buffers.
*/
if (((mysqlnd_zval *)*zv)->point_type == MYSQLND_POINTS_INT_BUFFER) {
zval_copy_ctor(*zv);
*copy_ctor_called = TRUE;
((mysqlnd_zval *)*zv)->point_type = MYSQLND_POINTS_EXT_BUFFER;
}
/*
This will decrease the counter of the user-level (mysqlnd). When the engine
layer (the script) has finished working this this zval, when the variable is
no more used, out of scope whatever, then it will try zval_ptr_dtor() but
and the refcount will reach 1 and the engine won't try to destruct the
memory allocated by us.
*/
zval_ptr_dtor(zv);
/*
Unfortunately, we can't return this variable to the free_list
because it's still used. And this cleaning up will happen at request
shutdown :(.
*/
LOCK_PCACHE(cache);
DBG_INF_FMT("gc_list.ptr_line=%p gc_list.last_added=%p *gc_list.last_added=%p free_list.canary1=%p free_list.canary2=%p",
thd_cache->gc_list.ptr_line,
thd_cache->gc_list.last_added,
*thd_cache->gc_list.last_added,
cache->free_list.canary1, cache->free_list.canary2);
if ((thd_cache->gc_list.last_added - thd_cache->gc_list.ptr_line) > (int) cache->max_items) {
DBG_ERR("Buffer overflow follows");
DBG_ERR_FMT("parent->max_items=%d parent->free_items=%d diff=%d",
cache->max_items, cache->free_items,
thd_cache->gc_list.last_added - thd_cache->gc_list.ptr_line);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "We will get buffer overflow");
}
++cache->put_misses;
*(thd_cache->gc_list.last_added++) = (mysqlnd_zval *)*zv;
UNLOCK_PCACHE(cache);
} else {
DBG_INF("No user reference");
/* No user reference */
if (((mysqlnd_zval *)*zv)->point_type == MYSQLND_POINTS_EXT_BUFFER) {
DBG_INF("Points to external buffer. Calling zval_dtor");
/*
PS are here
Unicode mode goes also here if the column is not binary but a text
*/
zval_dtor(*zv);
}
LOCK_PCACHE(cache);
++cache->put_hits;
++cache->free_items;
((mysqlnd_zval *)*zv)->point_type = MYSQLND_POINTS_FREE;
Z_DELREF_PP(zv); /* Make it 1 */
ZVAL_NULL(*zv);
#ifdef ZTS
memset(&((mysqlnd_zval *)*zv)->thread_id, 0, sizeof(THREAD_T));
#endif
*(--cache->free_list.last_added) = (mysqlnd_zval *)*zv;
UNLOCK_PCACHE(cache);
}
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ _mysqlnd_palloc_rinit */
PHPAPI MYSQLND_THD_ZVAL_PCACHE * _mysqlnd_palloc_rinit(MYSQLND_ZVAL_PCACHE * cache TSRMLS_DC)
{
return mysqlnd_palloc_init_thd_cache(cache);
}
/* }}} */
/* {{{ _mysqlnd_palloc_rshutdown */
PHPAPI void _mysqlnd_palloc_rshutdown(MYSQLND_THD_ZVAL_PCACHE * thd_cache TSRMLS_DC)
{
DBG_ENTER("_mysqlnd_palloc_rshutdown");
DBG_INF_FMT("cache=%p", thd_cache);
mysqlnd_palloc_free_thd_cache_reference(&thd_cache);
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ mysqlnd_palloc_rshutdown */
PHPAPI void mysqlnd_palloc_stats(const MYSQLND_ZVAL_PCACHE * const cache, zval *return_value)
{
if (cache) {
#if PHP_MAJOR_VERSION >= 6
UChar *ustr;
int ulen;
TSRMLS_FETCH();
#endif
LOCK_PCACHE(cache);
array_init(return_value);
#if PHP_MAJOR_VERSION >= 6
zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, "put_hits", sizeof("put_hits") TSRMLS_CC);
add_u_assoc_long_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen + 1, cache->put_hits);
efree(ustr);
zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, "put_misses", sizeof("put_misses") TSRMLS_CC);
add_u_assoc_long_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen + 1, cache->put_hits);
efree(ustr);
zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, "get_hits", sizeof("get_hits") TSRMLS_CC);
add_u_assoc_long_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen + 1, cache->put_hits);
efree(ustr);
zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, "get_misses", sizeof("get_misses") TSRMLS_CC);
add_u_assoc_long_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen + 1, cache->put_hits);
efree(ustr);
zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, "size", sizeof("size") TSRMLS_CC);
add_u_assoc_long_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen + 1, cache->put_hits);
efree(ustr);
zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, "free_items", sizeof("free_items") TSRMLS_CC);
add_u_assoc_long_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen + 1, cache->put_hits);
efree(ustr);
zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, "references", sizeof("references") TSRMLS_CC);
add_u_assoc_long_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen + 1, cache->put_hits);
efree(ustr);
#else
add_assoc_long_ex(return_value, "put_hits", sizeof("put_hits"), cache->put_hits);
add_assoc_long_ex(return_value, "put_misses", sizeof("put_misses"), cache->put_misses);
add_assoc_long_ex(return_value, "get_hits", sizeof("get_hits"), cache->get_hits);
add_assoc_long_ex(return_value, "get_misses", sizeof("get_misses"), cache->get_misses);
add_assoc_long_ex(return_value, "size", sizeof("size"), cache->max_items);
add_assoc_long_ex(return_value, "free_items", sizeof("free_items"), cache->free_items);
add_assoc_long_ex(return_value, "references", sizeof("references"), cache->references);
#endif
UNLOCK_PCACHE(cache);
} else {
ZVAL_NULL(return_value);
}
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
-116
View File
@@ -1,116 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP Version 6 |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Georg Richter <georg@mysql.com> |
| Andrey Hristov <andrey@mysql.com> |
| Ulf Wendel <uwendel@mysql.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef MYSQLND_PALLOC_H
#define MYSQLND_PALLOC_H
/* Used in mysqlnd_debug.c */
extern char * mysqlnd_palloc_zval_ptr_dtor_name;
extern char * mysqlnd_palloc_get_zval_name;
/* Session caching allocator */
struct st_mysqlnd_zval_list {
zval **ptr_line;
zval **last_added;
};
typedef struct st_mysqlnd_zval_cache MYSQLND_ZVAL_CACHE;
struct st_mysqlnd_zval_cache {
struct st_mysqlnd_zval_list *free_list;
unsigned int free_items;
unsigned int max_items;
unsigned int references;
unsigned long get_hits;
unsigned long get_misses;
unsigned long put_hits;
unsigned long put_full_misses;
unsigned long put_refcount_misses;
};
enum mysqlnd_zval_ptr_type
{
MYSQLND_POINTS_INT_BUFFER,
MYSQLND_POINTS_EXT_BUFFER,
MYSQLND_POINTS_FREE
};
/* Persistent caching allocator */
typedef struct st_mysqlnd_zval {
/* Should be first */
zval zv;
enum mysqlnd_zval_ptr_type point_type;
#ifdef ZTS
THREAD_T thread_id;
#endif
} mysqlnd_zval;
typedef struct st_mysqlnd_ndzval_list {
mysqlnd_zval **ptr_line; /* we allocate this, all are pointers to the block */
void *canary1;
void *canary2;
mysqlnd_zval **last_added; /* this points to the ptr_line, and moves left-right. It's our stack */
} mysqlnd_ndzval_list;
struct st_mysqlnd_zval_pcache {
mysqlnd_zval *block;
mysqlnd_zval *last_in_block;
mysqlnd_ndzval_list free_list; /* Fetch from here */
#ifdef ZTS
MUTEX_T LOCK_access;
#endif
unsigned int references;
/* These are just for statistics and not used for operational purposes */
unsigned int free_items;
unsigned int max_items;
unsigned long get_hits;
unsigned long get_misses;
unsigned long put_hits;
unsigned long put_misses;
};
struct st_mysqlnd_thread_zval_pcache {
struct st_mysqlnd_zval_pcache *parent;
unsigned int references;
#ifdef ZTS
THREAD_T thread_id;
#endif
mysqlnd_ndzval_list gc_list; /* GC these from time to time */
};
#endif /* MYSQLND_PALLOC_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
+38 -41
View File
@@ -235,47 +235,44 @@ typedef unsigned long long uint64_t;
#define uint1korr(A) (*(((uint8_t*)(A))))
/* Bit values are sent in reverted order of bytes, compared to normal !!! */
#define bit_uint2korr(A) ((uint16_t) (((uint16_t) (((zend_uchar*) (A))[1])) +\
((uint16_t) (((zend_uchar*) (A))[0]) << 8)))
#define bit_uint3korr(A) ((uint32_t) (((uint32_t) (((zend_uchar*) (A))[2])) +\
(((uint32_t) (((zend_uchar*) (A))[1])) << 8) +\
(((uint32_t) (((zend_uchar*) (A))[0])) << 16)))
#define bit_uint4korr(A) ((uint32_t) (((uint32_t) (((zend_uchar*) (A))[3])) +\
(((uint32_t) (((zend_uchar*) (A))[2])) << 8) +\
(((uint32_t) (((zend_uchar*) (A))[1])) << 16) +\
(((uint32_t) (((zend_uchar*) (A))[0])) << 24)))
#define bit_uint5korr(A) ((uint64_t)(((uint32_t) ((zend_uchar) (A)[4])) +\
(((uint32_t) ((zend_uchar*) (A)[3])) << 8) +\
(((uint32_t) ((zend_uchar*) (A)[2])) << 16) +\
(((uint32_t) ((zend_uchar*) (A)[1])) << 24)) +\
(((uint64_t) ((zend_uchar*) (A)[0])) << 32))
#define bit_uint6korr(A) ((uint64_t)(((uint32_t) (((zend_uchar*) (A))[5])) +\
(((uint32_t) (((zend_uchar*) (A))[4])) << 8) +\
(((uint32_t) (((zend_uchar*) (A))[3])) << 16) +\
(((uint32_t) (((zend_uchar*) (A))[2])) << 24)) +\
(((uint64_t) (((uint32_t) (((zend_uchar*) (A))[1])) +\
(((uint32_t) (((zend_uchar*) (A))[0]) << 8)))) << 32))
#define bit_uint7korr(A) ((uint64_t)(((uint32_t) (((zend_uchar*) (A))[6])) +\
(((uint32_t) (((zend_uchar*) (A))[5])) << 8) +\
(((uint32_t) (((zend_uchar*) (A))[4])) << 16) +\
(((uint32_t) (((zend_uchar*) (A))[3])) << 24)) +\
(((uint64_t) (((uint32_t) (((zend_uchar*) (A))[2])) +\
(((uint32_t) (((zend_uchar*) (A))[1])) << 8) +\
(((uint32_t) (((zend_uchar*) (A))[0])) << 16))) << 32))
#define bit_uint8korr(A) ((uint64_t)(((uint32_t) (((zend_uchar*) (A))[7])) +\
(((uint32_t) (((zend_uchar*) (A))[6])) << 8) +\
(((uint32_t) (((zend_uchar*) (A))[5])) << 16) +\
(((uint32_t) (((zend_uchar*) (A))[4])) << 24)) +\
(((uint64_t) (((uint32_t) (((zend_uchar*) (A))[3])) +\
(((uint32_t) (((zend_uchar*) (A))[2])) << 8) +\
(((uint32_t) (((zend_uchar*) (A))[1])) << 16) +\
(((uint32_t) (((zend_uchar*) (A))[0])) << 24))) << 32))
#define bit_uint2korr(A) ((uint16_t) (((uint16_t) (((unsigned char*) (A))[1])) +\
((uint16_t) (((unsigned char*) (A))[0]) << 8)))
#define bit_uint3korr(A) ((uint32_t) (((uint32_t) (((unsigned char*) (A))[2])) +\
(((uint32_t) (((unsigned char*) (A))[1])) << 8) +\
(((uint32_t) (((unsigned char*) (A))[0])) << 16)))
#define bit_uint4korr(A) ((uint32_t) (((uint32_t) (((unsigned char*) (A))[3])) +\
(((uint32_t) (((unsigned char*) (A))[2])) << 8) +\
(((uint32_t) (((unsigned char*) (A))[1])) << 16) +\
(((uint32_t) (((unsigned char*) (A))[0])) << 24)))
#define bit_uint5korr(A) ((uint64_t)(((uint32_t) (((unsigned char*) (A))[4])) +\
(((uint32_t) (((unsigned char*) (A))[3])) << 8) +\
(((uint32_t) (((unsigned char*) (A))[2])) << 16) +\
(((uint32_t) (((unsigned char*) (A))[1])) << 24)) +\
(((uint64_t) (((unsigned char*) (A))[0])) << 32))
#define bit_uint6korr(A) ((uint64_t)(((uint32_t) (((unsigned char*) (A))[5])) +\
(((uint32_t) (((unsigned char*) (A))[4])) << 8) +\
(((uint32_t) (((unsigned char*) (A))[3])) << 16) +\
(((uint32_t) (((unsigned char*) (A))[2])) << 24)) +\
(((uint64_t) (((uint32_t) (((unsigned char*) (A))[1])) +\
(((uint32_t) (((unsigned char*) (A))[0]) << 8)))) <<\
32))
#define bit_uint7korr(A) ((uint64_t)(((uint32_t) (((unsigned char*) (A))[6])) +\
(((uint32_t) (((unsigned char*) (A))[5])) << 8) +\
(((uint32_t) (((unsigned char*) (A))[4])) << 16) +\
(((uint32_t) (((unsigned char*) (A))[3])) << 24)) +\
(((uint64_t) (((uint32_t) (((unsigned char*) (A))[2])) +\
(((uint32_t) (((unsigned char*) (A))[1])) << 8) +\
(((uint32_t) (((unsigned char*) (A))[0])) << 16))) <<\
32))
#define bit_uint8korr(A) ((uint64_t)(((uint32_t) (((unsigned char*) (A))[7])) +\
(((uint32_t) (((unsigned char*) (A))[6])) << 8) +\
(((uint32_t) (((unsigned char*) (A))[5])) << 16) +\
(((uint32_t) (((unsigned char*) (A))[4])) << 24)) +\
(((uint64_t) (((uint32_t) (((unsigned char*) (A))[3])) +\
(((uint32_t) (((unsigned char*) (A))[2])) << 8) +\
(((uint32_t) (((unsigned char*) (A))[1])) << 16) +\
(((uint32_t) (((unsigned char*) (A))[0])) << 24))) <<\
32))
/*
-3
View File
@@ -169,9 +169,6 @@ void ps_fetch_from_1_to_8_bytes(zval *zv, const MYSQLND_FIELD * const field,
unsigned int pack_len, zend_uchar **row, zend_bool as_unicode,
unsigned int byte_count TSRMLS_DC);
int mysqlnd_set_sock_no_delay(php_stream *stream);
#endif /* MYSQLND_PRIV_H */
+31 -108
View File
@@ -38,13 +38,6 @@ const char * const mysqlnd_stmt_not_prepared = "Statement not prepared";
static struct st_mysqlnd_stmt_methods *mysqlnd_stmt_methods;
/* Exported by mysqlnd.c */
enum_func_status mysqlnd_simple_command(MYSQLND *conn, enum php_mysqlnd_server_command command,
const char * const arg, size_t arg_len,
enum php_mysql_packet_type ok_packet,
zend_bool silent, zend_bool ignore_upsert_status
TSRMLS_DC);
/* Exported by mysqlnd_ps_codec.c */
zend_uchar* mysqlnd_stmt_execute_generate_request(MYSQLND_STMT *stmt, size_t *request_len,
zend_bool *free_buffer TSRMLS_DC);
@@ -107,9 +100,6 @@ MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const stmt TSRMLS_DC)
result->type = MYSQLND_RES_PS_BUF;
result->m.fetch_row = mysqlnd_fetch_stmt_row_buffered;
result->m.fetch_lengths = NULL;/* makes no sense */
if (!result->zval_cache) {
result->zval_cache = mysqlnd_palloc_get_thd_cache_reference(conn->zval_cache);
}
result->result_set_memory_pool = mysqlnd_mempool_create(16000 TSRMLS_CC);
@@ -133,80 +123,6 @@ MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const stmt TSRMLS_DC)
/* }}} */
/* {{{ mysqlnd_stmt::background_store_result */
static MYSQLND_RES *
MYSQLND_METHOD(mysqlnd_stmt, background_store_result)(MYSQLND_STMT * const stmt TSRMLS_DC)
{
enum_func_status ret;
MYSQLND *conn = stmt->conn;
MYSQLND_RES *result;
zend_bool to_cache = FALSE;
DBG_ENTER("mysqlnd_stmt::background_store_result");
DBG_INF_FMT("stmt=%lu", stmt->stmt_id);
/* be compliant with libmysql - NULL will turn */
if (!stmt->field_count) {
DBG_RETURN(NULL);
}
if (stmt->cursor_exists) {
/* Silently convert buffered to unbuffered, for now */
MYSQLND_RES * res = stmt->m->use_result(stmt TSRMLS_CC);
DBG_RETURN(res);
}
/* Nothing to store for UPSERT/LOAD DATA*/
if (CONN_GET_STATE(conn) != CONN_FETCHING_DATA ||
stmt->state != MYSQLND_STMT_WAITING_USE_OR_STORE)
{
SET_CLIENT_ERROR(conn->error_info, CR_COMMANDS_OUT_OF_SYNC,
UNKNOWN_SQLSTATE, mysqlnd_out_of_sync);
DBG_RETURN(NULL);
}
stmt->default_rset_handler = stmt->m->store_result;
SET_EMPTY_ERROR(stmt->error_info);
SET_EMPTY_ERROR(stmt->conn->error_info);
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_PS_BUFFERED_SETS);
result = stmt->result;
result->type = MYSQLND_RES_PS_BUF;
result->m.fetch_row = mysqlnd_fetch_stmt_row_buffered;
result->m.fetch_lengths = NULL;/* makes no sense */
if (!result->zval_cache) {
result->zval_cache = mysqlnd_palloc_get_thd_cache_reference(conn->zval_cache);
}
/* Create room for 'next_extend' rows */
/* Not set for SHOW statements at PREPARE stage */
if (result->conn) {
result->conn->m->free_reference(result->conn TSRMLS_CC);
result->conn = NULL; /* store result does not reference the connection */
}
ret = result->m.store_result_fetch_data(conn, result, result->meta, TRUE, to_cache TSRMLS_CC);
if (PASS == ret) {
/* libmysql API docs say it should be so for SELECT statements */
stmt->upsert_status.affected_rows = stmt->result->stored_data->row_count;
stmt->state = MYSQLND_STMT_USE_OR_STORE_CALLED;
} else {
conn->error_info = result->stored_data->error_info;
stmt->result->m.free_result_contents(stmt->result TSRMLS_CC);
mnd_efree(stmt->result);
stmt->result = NULL;
stmt->state = MYSQLND_STMT_PREPARED;
}
DBG_RETURN(result);
}
/* }}} */
/* {{{ mysqlnd_stmt::get_result */
static MYSQLND_RES *
MYSQLND_METHOD(mysqlnd_stmt, get_result)(MYSQLND_STMT * const stmt TSRMLS_DC)
@@ -238,8 +154,7 @@ MYSQLND_METHOD(mysqlnd_stmt, get_result)(MYSQLND_STMT * const stmt TSRMLS_DC)
SET_EMPTY_ERROR(stmt->conn->error_info);
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_BUFFERED_SETS);
result = mysqlnd_result_init(stmt->result->field_count,
mysqlnd_palloc_get_thd_cache_reference(conn->zval_cache) TSRMLS_CC);
result = mysqlnd_result_init(stmt->result->field_count TSRMLS_CC);
result->meta = stmt->result->meta->m->clone_metadata(stmt->result->meta, FALSE TSRMLS_CC);
@@ -421,8 +336,8 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const stmt, const char * co
stmt_to_prepare = mysqlnd_stmt_init(stmt->conn);
}
if (FAIL == mysqlnd_simple_command(stmt_to_prepare->conn, COM_STMT_PREPARE, query,
query_len, PROT_LAST, FALSE, TRUE TSRMLS_CC) ||
if (FAIL == stmt_to_prepare->conn->m->simple_command(stmt_to_prepare->conn, COM_STMT_PREPARE, query,
query_len, PROT_LAST, FALSE, TRUE TSRMLS_CC) ||
FAIL == mysqlnd_stmt_read_prepare_response(stmt_to_prepare TSRMLS_CC)) {
goto fail;
}
@@ -441,9 +356,7 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const stmt, const char * co
no metadata at prepare.
*/
if (stmt_to_prepare->field_count) {
MYSQLND_RES *result = mysqlnd_result_init(stmt_to_prepare->field_count,
mysqlnd_palloc_get_thd_cache_reference(stmt->conn->zval_cache)
TSRMLS_CC);
MYSQLND_RES *result = mysqlnd_result_init(stmt_to_prepare->field_count TSRMLS_CC);
/* Allocate the result now as it is needed for the reading of metadata */
stmt_to_prepare->result = result;
@@ -685,9 +598,9 @@ MYSQLND_METHOD(mysqlnd_stmt, execute)(MYSQLND_STMT * const stmt TSRMLS_DC)
/* support for buffer types should be added here ! */
ret = mysqlnd_simple_command(stmt->conn, COM_STMT_EXECUTE, (char *)request, request_len,
PROT_LAST /* we will handle the response packet*/,
FALSE, FALSE TSRMLS_CC);
ret = stmt->conn->m->simple_command(stmt->conn, COM_STMT_EXECUTE, (char *)request, request_len,
PROT_LAST /* we will handle the response packet*/,
FALSE, FALSE TSRMLS_CC);
if (free_request) {
mnd_efree(request);
@@ -742,7 +655,6 @@ mysqlnd_fetch_stmt_row_buffered(MYSQLND_RES *result, void *param, unsigned int f
result->stored_data->persistent,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
if (stmt->update_max_length) {
for (i = 0; i < result->field_count; i++) {
@@ -858,7 +770,6 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES *result, void *param, unsigned int
FALSE,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
for (i = 0; i < field_count; i++) {
@@ -1005,9 +916,9 @@ mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES *result, void *param, unsigned int fla
int4store(buf, stmt->stmt_id);
int4store(buf + STMT_ID_LENGTH, 1); /* for now fetch only one row */
if (FAIL == mysqlnd_simple_command(stmt->conn, COM_STMT_FETCH, (char *)buf, sizeof(buf),
PROT_LAST /* we will handle the response packet*/,
FALSE, TRUE TSRMLS_CC)) {
if (FAIL == stmt->conn->m->simple_command(stmt->conn, COM_STMT_FETCH, (char *)buf, sizeof(buf),
PROT_LAST /* we will handle the response packet*/,
FALSE, TRUE TSRMLS_CC)) {
stmt->error_info = stmt->conn->error_info;
DBG_RETURN(FAIL);
}
@@ -1036,7 +947,6 @@ mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES *result, void *param, unsigned int fla
FALSE,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
/* If no result bind, do nothing. We consumed the data */
@@ -1216,7 +1126,7 @@ MYSQLND_METHOD(mysqlnd_stmt, reset)(MYSQLND_STMT * const stmt TSRMLS_DC)
int4store(cmd_buf, stmt->stmt_id);
if (CONN_GET_STATE(conn) == CONN_READY &&
FAIL == (ret = mysqlnd_simple_command(conn, COM_STMT_RESET, (char *)cmd_buf,
FAIL == (ret = conn->m->simple_command(conn, COM_STMT_RESET, (char *)cmd_buf,
sizeof(cmd_buf), PROT_OK_PACKET,
FALSE, TRUE TSRMLS_CC))) {
stmt->error_info = conn->error_info;
@@ -1273,7 +1183,7 @@ MYSQLND_METHOD(mysqlnd_stmt, send_long_data)(MYSQLND_STMT * const stmt, unsigned
XXX: Unfortunately we have to allocate additional buffer to be able the
additional data, which is like a header inside the payload.
This should be optimised, but it will be a pervasive change, so
mysqlnd_simple_command() will accept not a buffer, but actually MYSQLND_STRING*
conn->m->simple_command() will accept not a buffer, but actually MYSQLND_STRING*
terminated by NULL, to send. If the strings are not big, we can collapse them
on the buffer every connection has, but otherwise we will just send them
one by one to the wire.
@@ -1289,7 +1199,7 @@ MYSQLND_METHOD(mysqlnd_stmt, send_long_data)(MYSQLND_STMT * const stmt, unsigned
memcpy(cmd_buf + STMT_ID_LENGTH + 2, data, length);
/* COM_STMT_SEND_LONG_DATA doesn't send an OK packet*/
ret = mysqlnd_simple_command(conn, cmd, (char *)cmd_buf, packet_len,
ret = conn->m->simple_command(conn, cmd, (char *)cmd_buf, packet_len,
PROT_LAST , FALSE, TRUE TSRMLS_CC);
mnd_efree(cmd_buf);
if (FAIL == ret) {
@@ -1315,7 +1225,7 @@ MYSQLND_METHOD(mysqlnd_stmt, send_long_data)(MYSQLND_STMT * const stmt, unsigned
#if HAVE_USLEEP && !defined(PHP_WIN32)
usleep(120000);
#endif
if ((packet_len = php_mysqlnd_consume_uneaten_data(conn, cmd TSRMLS_CC))) {
if ((packet_len = conn->net->m.consume_uneaten_data(conn->net, cmd TSRMLS_CC))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "There was an error "
"while sending long data. Probably max_allowed_packet_size "
"is smaller than the data. You have to increase it or send "
@@ -1730,7 +1640,7 @@ MYSQLND_METHOD(mysqlnd_stmt, result_metadata)(MYSQLND_STMT * const stmt TSRMLS_D
In the meantime we don't need a zval cache reference for this fake
result set, so we don't get one.
*/
result = mysqlnd_result_init(stmt->field_count, NULL TSRMLS_CC);
result = mysqlnd_result_init(stmt->field_count TSRMLS_CC);
result->type = MYSQLND_RES_NORMAL;
result->m.fetch_row = result->m.fetch_row_normal_unbuffered;
result->unbuf = mnd_ecalloc(1, sizeof(MYSQLND_RES_UNBUFFERED));
@@ -2059,7 +1969,7 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_stmt, net_close)(MYSQLND_STMT * const stmt, zend_
int4store(cmd_buf, stmt->stmt_id);
if (CONN_GET_STATE(conn) == CONN_READY &&
FAIL == mysqlnd_simple_command(conn, COM_STMT_CLOSE, (char *)cmd_buf, sizeof(cmd_buf),
FAIL == conn->m->simple_command(conn, COM_STMT_CLOSE, (char *)cmd_buf, sizeof(cmd_buf),
PROT_LAST /* COM_STMT_CLOSE doesn't send an OK packet*/,
FALSE, TRUE TSRMLS_CC)) {
stmt->error_info = conn->error_info;
@@ -2122,7 +2032,6 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_stmt)
MYSQLND_METHOD(mysqlnd_stmt, execute),
MYSQLND_METHOD(mysqlnd_stmt, use_result),
MYSQLND_METHOD(mysqlnd_stmt, store_result),
MYSQLND_METHOD(mysqlnd_stmt, background_store_result),
MYSQLND_METHOD(mysqlnd_stmt, get_result),
MYSQLND_METHOD(mysqlnd_stmt, more_results),
MYSQLND_METHOD(mysqlnd_stmt, next_result),
@@ -2165,7 +2074,8 @@ MYSQLND_CLASS_METHODS_END;
/* {{{ _mysqlnd_stmt_init */
MYSQLND_STMT * _mysqlnd_stmt_init(MYSQLND * const conn TSRMLS_DC)
{
MYSQLND_STMT *stmt = mnd_ecalloc(1, sizeof(MYSQLND_STMT));
size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *);
MYSQLND_STMT *stmt = mnd_ecalloc(1, alloc_size);
DBG_ENTER("_mysqlnd_stmt_init");
DBG_INF_FMT("stmt=%p", stmt);
@@ -2191,6 +2101,19 @@ MYSQLND_STMT * _mysqlnd_stmt_init(MYSQLND * const conn TSRMLS_DC)
/* }}} */
/* {{{ _mysqlnd_plugin_get_plugin_stmt_data */
PHPAPI void ** _mysqlnd_plugin_get_plugin_stmt_data(const MYSQLND_STMT * stmt, unsigned int plugin_id TSRMLS_DC)
{
DBG_ENTER("_mysqlnd_plugin_get_plugin_stmt_data");
DBG_INF_FMT("plugin_id=%u", plugin_id);
if (!stmt || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)((char *)stmt + sizeof(MYSQLND_STMT) + plugin_id * sizeof(void *)));
}
/* }}} */
/* {{{ mysqlnd_efree_param_bind_dtor */
PHPAPI void
mysqlnd_efree_param_bind_dtor(MYSQLND_PARAM_BIND * param_bind TSRMLS_DC)
-141
View File
@@ -1,141 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP Version 6 |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Georg Richter <georg@mysql.com> |
| Andrey Hristov <andrey@mysql.com> |
| Ulf Wendel <uwendel@mysql.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include "php.h"
#include "mysqlnd.h"
#include "mysqlnd_priv.h"
#include "mysqlnd_statistics.h"
#define MYSQLND_SILENT
#ifdef ZTS
#define LOCK_QCACHE(cache) tsrm_mutex_lock((cache)->LOCK_access)
#define UNLOCK_QCACHE(cache) tsrm_mutex_unlock((cache)->LOCK_access)
#else
#define LOCK_QCACHE(cache)
#define UNLOCK_QCACHE(cache)
#endif
/* {{{ mysqlnd_qcache_init_cache */
PHPAPI MYSQLND_QCACHE * mysqlnd_qcache_init_cache()
{
MYSQLND_QCACHE *cache = calloc(1, sizeof(MYSQLND_QCACHE));
#ifndef MYSQLND_SILENT
php_printf("[mysqlnd_qcache_init_cache %p]\n", cache);
#endif
cache->references = 1;
#ifdef ZTS
cache->LOCK_access = tsrm_mutex_alloc();
#endif
cache->ht = malloc(sizeof(HashTable));
zend_hash_init(cache->ht, 10 /* init_elements */, NULL, NULL, TRUE /*pers*/);
return cache;
}
/* }}} */
/* {{{ mysqlnd_qcache_get_cache_reference */
PHPAPI MYSQLND_QCACHE * mysqlnd_qcache_get_cache_reference(MYSQLND_QCACHE * const cache)
{
if (cache) {
#ifndef MYSQLND_SILENT
php_printf("[mysqlnd_qcache_get_cache_reference %p will become %d]\n", cache, cache->references+1);
#endif
LOCK_QCACHE(cache);
cache->references++;
UNLOCK_QCACHE(cache);
}
return cache;
}
/* }}} */
/* {{{ mysqlnd_qcache_free_cache */
/*
As this call will happen on MSHUTDOWN(), then we don't need to copy the zvals with
copy_ctor but scrap what they point to with zval_dtor() and then just free our
pre-allocated block. Precondition is that we ZVAL_NULL() the zvals when we put them
to the free list after usage. We ZVAL_NULL() them when we allocate them in the
constructor of the cache.
*/
static
void mysqlnd_qcache_free_cache(MYSQLND_QCACHE *cache)
{
#ifndef MYSQLND_SILENT
php_printf("[mysqlnd_qcache_free_cache %p]\n", cache);
#endif
#ifdef ZTS
tsrm_mutex_free(cache->LOCK_access);
#endif
zend_hash_destroy(cache->ht);
free(cache->ht);
free(cache);
}
/* }}} */
/* {{{ mysqlnd_qcache_free_cache_reference */
PHPAPI void mysqlnd_qcache_free_cache_reference(MYSQLND_QCACHE **cache)
{
if (*cache) {
zend_bool to_free;
#ifndef MYSQLND_SILENT
php_printf("[mysqlnd_qcache_free_cache_reference %p] refs=%d\n", *cache, (*cache)->references);
#endif
LOCK_QCACHE(*cache);
to_free = --(*cache)->references == 0;
/* Unlock before destroying */
UNLOCK_QCACHE(*cache);
if (to_free) {
mysqlnd_qcache_free_cache(*cache);
}
*cache = NULL;
}
}
/* }}} */
/* {{{ mysqlnd_qcache_free_cache_reference */
PHPAPI void mysqlnd_qcache_stats(const MYSQLND_QCACHE * const cache, zval *return_value)
{
if (cache) {
LOCK_QCACHE(cache);
array_init(return_value);
add_assoc_long_ex(return_value, "references", sizeof("references"), cache->references);
UNLOCK_QCACHE(cache);
} else {
ZVAL_NULL(return_value);
}
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
+54 -542
View File
@@ -33,65 +33,6 @@
#define MYSQLND_SILENT
#ifdef MYSQLND_THREADED
/* {{{ mysqlnd_fetch_thread */
void * mysqlnd_fetch_thread(void *arg)
{
MYSQLND *conn = (MYSQLND *) arg;
MYSQLND_RES * result = NULL;
void ***tsrm_ls = conn->tsrm_ls;
#ifndef MYSQLND_SILENT
printf("THREAD] conn=%p tsrm_ls=%p\n", conn, conn->tsrm_ls);
#endif
do {
pthread_mutex_lock(&conn->LOCK_work);
while (conn->thread_killed == FALSE && !conn->current_result) {
#ifndef MYSQLND_SILENT
printf("THREAD] Waiting for work in %s\n", __FUNCTION__);
#endif
pthread_cond_wait(&conn->COND_work, &conn->LOCK_work);
}
if (conn->thread_killed == TRUE) {
#ifndef MYSQLND_SILENT
printf("THREAD] Thread killed in %s\n", __FUNCTION__);
#endif
pthread_cond_signal(&conn->COND_thread_ended);
pthread_mutex_unlock(&conn->LOCK_work);
break;
}
#ifndef MYSQLND_SILENT
printf("THREAD] Got work in %s\n", __FUNCTION__);
#endif
CONN_SET_STATE(conn, CONN_FETCHING_DATA);
result = conn->current_result;
conn->current_result = NULL;
pthread_cond_signal(&conn->COND_work); /* sent notification back */
pthread_mutex_unlock(&conn->LOCK_work);
#ifndef MYSQLND_SILENT
printf("THREAD] Starting fetch %s\n", __FUNCTION__);
#endif
mysqlnd_background_store_result_fetch_data(result TSRMLS_CC);
/* do fetch the data from the wire */
pthread_mutex_lock(&conn->LOCK_work);
CONN_SET_STATE(conn, CONN_READY);
pthread_cond_signal(&conn->COND_work_done);
#ifndef MYSQLND_SILENT
printf("THREAD] Signaling work done in %s\n", __FUNCTION__);
#endif
pthread_mutex_unlock(&conn->LOCK_work);
} while (1);
#ifndef MYSQLND_SILENT
printf("THREAD] Exiting worker thread in %s\n", __FUNCTION__);
#endif
return NULL;
}
/* }}} */
#endif /* MYSQLND_THREADED */
/* {{{ mysqlnd_res::initialize_result_set_rest */
static void
@@ -118,7 +59,6 @@ MYSQLND_METHOD(mysqlnd_res, initialize_result_set_rest)(MYSQLND_RES * const resu
result->stored_data->persistent,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
for (i = 0; i < result->field_count; i++) {
/*
@@ -141,6 +81,53 @@ MYSQLND_METHOD(mysqlnd_res, initialize_result_set_rest)(MYSQLND_RES * const resu
/* }}} */
/* {{{ mysqlnd_palloc_zval_ptr_dtor */
void mysqlnd_palloc_zval_ptr_dtor(zval **zv, enum_mysqlnd_res_type type, zend_bool * copy_ctor_called TSRMLS_DC)
{
DBG_ENTER("mysqlnd_palloc_zval_ptr_dtor");
*copy_ctor_called = FALSE;
{
/*
This zval is not from the cache block.
Thus the refcount is -1 than of a zval from the cache,
because the zvals from the cache are owned by it.
*/
if (type == MYSQLND_RES_PS_BUF || type == MYSQLND_RES_PS_UNBUF) {
; /* do nothing, zval_ptr_dtor will do the job*/
} else if (Z_REFCOUNT_PP(zv) > 1) {
/*
Not a prepared statement, then we have to
call copy_ctor and then zval_ptr_dtor()
In Unicode mode the destruction of the zvals should not call
zval_copy_ctor() because then we will leak.
I suppose we can use UG(unicode) in mysqlnd.c when freeing a result set
to check if we need to call copy_ctor().
If the type is IS_UNICODE, which can happen with PHP6, then we don't
need to copy_ctor, as the data doesn't point to our internal buffers.
If it's string (in PHP5 always) and in PHP6 if data is binary, then
it still points to internal buffers and has to be copied.
*/
if (Z_TYPE_PP(zv) == IS_STRING) {
zval_copy_ctor(*zv);
}
*copy_ctor_called = TRUE;
} else {
if (Z_TYPE_PP(zv) == IS_STRING) {
ZVAL_NULL(*zv);
}
}
zval_ptr_dtor(zv);
DBG_VOID_RETURN;
}
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ mysqlnd_res::unbuffered_free_last_data */
static void
MYSQLND_METHOD(mysqlnd_res, unbuffered_free_last_data)(MYSQLND_RES * result TSRMLS_DC)
@@ -161,9 +148,7 @@ MYSQLND_METHOD(mysqlnd_res, unbuffered_free_last_data)(MYSQLND_RES * result TSRM
DBG_INF_FMT("%u columns to free", result->field_count);
for (i = 0; i < result->field_count; i++) {
mysqlnd_palloc_zval_ptr_dtor(&(unbuf->last_row_data[i]),
result->zval_cache, result->type,
&copy_ctor_called TSRMLS_CC);
mysqlnd_palloc_zval_ptr_dtor(&(unbuf->last_row_data[i]), result->type, &copy_ctor_called TSRMLS_CC);
if (copy_ctor_called) {
ctor_called_count++;
}
@@ -197,7 +182,6 @@ MYSQLND_METHOD(mysqlnd_res, unbuffered_free_last_data)(MYSQLND_RES * result TSRM
static void
MYSQLND_METHOD(mysqlnd_res, free_buffered_data)(MYSQLND_RES *result TSRMLS_DC)
{
MYSQLND_THD_ZVAL_PCACHE *zval_cache = result->zval_cache;
MYSQLND_RES_BUFFERED *set = result->stored_data;
unsigned int field_count = result->field_count;
int row;
@@ -216,8 +200,7 @@ MYSQLND_METHOD(mysqlnd_res, free_buffered_data)(MYSQLND_RES *result TSRMLS_DC)
if (current_row[0] == NULL) {
break;/* row that was never initialized */
}
mysqlnd_palloc_zval_ptr_dtor(&(current_row[col]), zval_cache,
result->type, &copy_ctor_called TSRMLS_CC);
mysqlnd_palloc_zval_ptr_dtor(&(current_row[col]), result->type, &copy_ctor_called TSRMLS_CC);
#if MYSQLND_DEBUG_MEMORY
DBG_INF_FMT("Copy_ctor_called=%d", copy_ctor_called);
#endif
@@ -240,9 +223,6 @@ MYSQLND_METHOD(mysqlnd_res, free_buffered_data)(MYSQLND_RES *result TSRMLS_DC)
}
set->data_cursor = NULL;
set->row_count = 0;
if (set->qcache) {
mysqlnd_qcache_free_cache_reference(&set->qcache);
}
DBG_INF("Freeing set");
mnd_pefree(set, set->persistent);
@@ -253,85 +233,6 @@ MYSQLND_METHOD(mysqlnd_res, free_buffered_data)(MYSQLND_RES *result TSRMLS_DC)
/* }}} */
#ifdef MYSQLND_THREADED
/* {{{ mysqlnd_free_background_buffered_data */
void mysqlnd_free_background_buffered_data(MYSQLND_RES *result TSRMLS_DC)
{
MYSQLND_THD_ZVAL_PCACHE *zval_cache = result->zval_cache;
MYSQLND_RES_BG_BUFFERED *set = result->bg_stored_data;
unsigned int field_count = result->field_count;
int row;
DBG_ENTER("mysqlnd_free_buffered_data");
DBG_INF_FMT("Freeing "MYSQLND_LLU_SPEC" row(s)", set->row_count);
do {
tsrm_mutex_lock(set->LOCK);
if (set->bg_fetch_finished) {
tsrm_mutex_unlock(set->LOCK);
break;
}
tsrm_mutex_unlock(set->LOCK);
#if HAVE_USLEEP
usleep(2000);
#else
{
volatile int i;
for (i = 0; i < 1000; i++);
}
#endif
} while (1);
DBG_INF_FMT("before: real_usage=%lu usage=%lu", zend_memory_usage(TRUE TSRMLS_CC), zend_memory_usage(FALSE TSRMLS_CC));
for (row = set->row_count - 1; row >= 0; row--) {
MYSQLND_MEMORY_POOL_CHUNK *current_buffer = set->row_buffers[row];
/* It could be the case that the user fetched no rows - then no set->data */
if (row < set->data_size && set->data[row]) {
zval **current_row = set->data[row];
unsigned int col;
for (col = 0; col < field_count; col++) {
zend_bool copy_ctor_called;
mysqlnd_palloc_zval_ptr_dtor(&(current_row[col]), zval_cache,
result->type, &copy_ctor_called TSRMLS_CC);
#if MYSQLND_DEBUG_MEMORY
DBG_INF_FMT("Copy_ctor_called=%d", copy_ctor_called);
#endif
MYSQLND_INC_GLOBAL_STATISTIC(copy_ctor_called? STAT_COPY_ON_WRITE_PERFORMED:
STAT_COPY_ON_WRITE_SAVED);
}
#if MYSQLND_DEBUG_MEMORY
DBG_INF("Freeing current_row & current_buffer");
#endif
mnd_pefree(current_row, set->persistent);
}
current_buffer->free_chunk(current_buffer, TRUE TSRMLS_CC);
}
DBG_INF("Freeing data & row_buffer");
mnd_pefree(set->data, set->persistent);
mnd_pefree(set->row_buffers, set->persistent);
set->data = NULL;
set->row_buffers = NULL;
set->data_cursor = NULL;
set->row_count = 0;
if (set->qcache) {
mysqlnd_qcache_free_cache_reference(&set->qcache);
}
if (set->LOCK) {
tsrm_mutex_free(set->LOCK);
}
DBG_INF("Freeing set");
mnd_pefree(set, set->persistent);
DBG_INF_FMT("after: real_usage=%lu usage=%lu", zend_memory_usage(TRUE TSRMLS_CC), zend_memory_usage(FALSE TSRMLS_CC));
DBG_VOID_RETURN;
}
/* }}} */
#endif /* MYSQL_THREADING */
/* {{{ mysqlnd_res::free_result_buffers */
static void
MYSQLND_METHOD(mysqlnd_res, free_result_buffers)(MYSQLND_RES *result TSRMLS_DC)
@@ -347,12 +248,6 @@ MYSQLND_METHOD(mysqlnd_res, free_result_buffers)(MYSQLND_RES *result TSRMLS_DC)
result->m.free_buffered_data(result TSRMLS_CC);
result->stored_data = NULL;
}
#ifdef MYSQLND_THREADED
else if (result->bg_stored_data) {
mysqlnd_free_background_buffered_data(result TSRMLS_CC);
result->bg_stored_data = NULL;
}
#endif
if (result->lengths) {
mnd_efree(result->lengths);
@@ -389,12 +284,6 @@ void mysqlnd_internal_free_result_contents(MYSQLND_RES *result TSRMLS_DC)
result->meta = NULL;
}
if (result->zval_cache) {
DBG_INF("Freeing zval cache reference");
mysqlnd_palloc_free_thd_cache_reference(&result->zval_cache);
result->zval_cache = NULL;
}
DBG_VOID_RETURN;
}
/* }}} */
@@ -551,11 +440,7 @@ mysqlnd_query_read_result_set_header(MYSQLND *conn, MYSQLND_STMT *stmt TSRMLS_DC
/* PS has already allocated it */
conn->field_count = rset_header.field_count;
if (!stmt) {
result =
conn->current_result=
mysqlnd_result_init(rset_header.field_count,
mysqlnd_palloc_get_thd_cache_reference(conn->zval_cache)
TSRMLS_CC);
result = conn->current_result = mysqlnd_result_init(rset_header.field_count TSRMLS_CC);
} else {
if (!stmt->result) {
DBG_INF("This is 'SHOW'/'EXPLAIN'-like query.");
@@ -564,11 +449,7 @@ mysqlnd_query_read_result_set_header(MYSQLND *conn, MYSQLND_STMT *stmt TSRMLS_DC
prepared statements can't send result set metadata for these queries
on prepare stage. Read it now.
*/
result =
stmt->result =
mysqlnd_result_init(rset_header.field_count,
mysqlnd_palloc_get_thd_cache_reference(conn->zval_cache)
TSRMLS_CC);
result = stmt->result = mysqlnd_result_init(rset_header.field_count TSRMLS_CC);
} else {
/*
Update result set metadata if it for some reason changed between
@@ -690,45 +571,6 @@ unsigned long * mysqlnd_fetch_lengths_buffered(MYSQLND_RES * const result)
/* }}} */
#ifdef MYSQLND_THREADED
/* {{{ mysqlnd_fetch_lengths_async_buffered */
/*
Do lazy initialization for buffered results. As PHP strings have
length inside, this function makes not much sense in the context
of PHP, to be called as separate function. But let's have it for
completeness.
*/
static
unsigned long * mysqlnd_fetch_lengths_async_buffered(MYSQLND_RES * const result)
{
int i;
zval **previous_row;
MYSQLND_RES_BG_BUFFERED *set = result->bg_stored_data;
/*
If:
- unbuffered result
- first row has not been read
- last_row has been read
*/
if (set->data_cursor == NULL ||
set->data_cursor == set->data ||
((set->data_cursor - set->data) > set->row_count))
{
return NULL;/* No rows or no more rows */
}
previous_row = *(set->data_cursor - 1);
for (i = 0; i < result->meta->field_count; i++) {
result->lengths[i] = (Z_TYPE_P(previous_row[i]) == IS_NULL)? 0:Z_STRLEN_P(previous_row[i]);
}
return result->lengths;
}
/* }}} */
#endif
/* {{{ mysqlnd_fetch_lengths_unbuffered */
static
unsigned long * mysqlnd_fetch_lengths_unbuffered(MYSQLND_RES * const result)
@@ -798,7 +640,6 @@ mysqlnd_fetch_row_unbuffered_c(MYSQLND_RES *result TSRMLS_DC)
FALSE,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
retrow = mnd_malloc(result->field_count * sizeof(char *));
@@ -912,7 +753,6 @@ mysqlnd_fetch_row_unbuffered(MYSQLND_RES *result, void *param, unsigned int flag
FALSE,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
for (i = 0; i < field_count; i++, field++, zend_hash_key++) {
@@ -1067,7 +907,6 @@ mysqlnd_fetch_row_buffered_c(MYSQLND_RES *result TSRMLS_DC)
FALSE,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
for (i = 0; i < result->field_count; i++) {
/*
@@ -1137,7 +976,6 @@ mysqlnd_fetch_row_buffered(MYSQLND_RES *result, void *param, unsigned int flags,
result->stored_data->persistent,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
for (i = 0; i < result->field_count; i++) {
/*
@@ -1228,7 +1066,6 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND * const conn, MYSQL
set->row_buffers = mnd_pemalloc(free_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *), to_cache);
}
set->persistent = to_cache;
set->qcache = to_cache? mysqlnd_qcache_get_cache_reference(conn->qcache):NULL;
set->references = 1;
result->m.row_decoder = binary_protocol? php_mysqlnd_rowp_read_binary_protocol:
@@ -1355,329 +1192,6 @@ MYSQLND_METHOD(mysqlnd_res, store_result)(MYSQLND_RES * result,
/* }}} */
#ifdef MYSQLND_THREADED
/* {{{ mysqlnd_fetch_row_async_buffered */
static enum_func_status
mysqlnd_fetch_row_async_buffered(MYSQLND_RES *result, void *param, unsigned int flags,
zend_bool *fetched_anything TSRMLS_DC)
{
zval *row = (zval *) param;
MYSQLND_RES_BG_BUFFERED *set = result->bg_stored_data;
DBG_ENTER("mysqlnd_fetch_row_async_buffered");
DBG_INF_FMT("flags=%u row=%p", flags, row);
do {
tsrm_mutex_lock(set->LOCK);
if (set->bg_fetch_finished == TRUE) {
/* Don't unlock here, will be done later */
break;
}
if (!set->data_cursor || (set->data_cursor - set->data) < (set->row_count)) {
tsrm_mutex_unlock(set->LOCK);
#if HAVE_USLEEP
usleep(2000);
#else
volatile int i = 0;
for (int i = 0; i < 100; i++);
#endif
} else {
break;
}
} while (1);
/* At the point we are still under LOCK */
if (set->data_cursor && (set->data_cursor - set->data) < (set->row_count)) {
uint64_t row_num = set->data_cursor - set->data;
zval **current_row = *set->data_cursor++;
unsigned int i;
set->initialized_rows++;
/* We don't forget to release the lock */
tsrm_mutex_unlock(set->LOCK);
/* If there was no decoding in background, we have to decode here */
if (set->decode_in_foreground == TRUE) {
MYSQLND_MEMORY_POOL_CHUNK *current_buffer = set->row_buffers[row_num];
result->m.row_decoder(current_buffer,
current_row,
result->meta->field_count,
result->meta->fields,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
for (i = 0; i < result->field_count; i++) {
/*
NULL fields are 0 length, 0 is not more than 0
String of zero size, definitely can't be the next max_length.
Thus for NULL and zero-length we are quite efficient.
*/
if (Z_TYPE_P(current_row[i]) >= IS_STRING) {
unsigned long len = Z_STRLEN_P(current_row[i]);
if (result->meta->fields[i].max_length < len) {
result->meta->fields[i].max_length = len;
}
}
}
}
for (i = 0; i < result->field_count; i++) {
zval *data = current_row[i];
/*
Let us later know what to do with this zval. If ref_count > 1, we will just
decrease it, otherwise free it. zval_ptr_dtor() make this very easy job.
*/
Z_ADDREF_P(data);
if ((flags & MYSQLND_FETCH_BOTH) == MYSQLND_FETCH_BOTH) {
Z_ADDREF_P(data);
}
if (flags & MYSQLND_FETCH_NUM) {
zend_hash_next_index_insert(Z_ARRVAL_P(row), &data, sizeof(zval *), NULL);
}
if (flags & MYSQLND_FETCH_ASSOC) {
/* zend_hash_quick_update needs length + trailing zero */
/* QQ: Error handling ? */
/*
zend_hash_quick_update does not check, as add_assoc_zval_ex do, whether
the index is a numeric and convert it to it. This however means constant
hashing of the column name, which is not needed as it can be precomputed.
*/
if (result->meta->zend_hash_keys[i].is_numeric == FALSE) {
#if PHP_MAJOR_VERSION >= 6
zend_u_hash_quick_update(Z_ARRVAL_P(row), IS_UNICODE,
result->meta->zend_hash_keys[i].ustr,
result->meta->zend_hash_keys[i].ulen + 1,
result->meta->zend_hash_keys[i].key,
(void *) &data, sizeof(zval *), NULL);
#else
zend_hash_quick_update(Z_ARRVAL_P(row),
result->meta->fields[i].name,
result->meta->fields[i].name_length + 1,
result->meta->zend_hash_keys[i].key,
(void *) &data, sizeof(zval *), NULL);
#endif
} else {
zend_hash_index_update(Z_ARRVAL_P(row),
result->meta->zend_hash_keys[i].key,
(void *) &data, sizeof(zval *), NULL);
}
}
}
*fetched_anything = TRUE;
MYSQLND_INC_GLOBAL_STATISTIC(STAT_ROWS_FETCHED_FROM_CLIENT_NORMAL_BUF);
} else {
set->data_cursor = NULL;
/* We don't forget to release the lock */
tsrm_mutex_unlock(set->LOCK);
*fetched_anything = FALSE;
DBG_INF("EOF reached");
}
DBG_INF_FMT("ret=PASS fetched=%d", *fetched_anything);
DBG_RETURN(PASS);
}
/* }}} */
/* {{{ mysqlnd_background_store_result_fetch_data */
enum_func_status
mysqlnd_background_store_result_fetch_data(MYSQLND_RES *result TSRMLS_DC)
{
enum_func_status ret;
php_mysql_packet_row *row_packet;
unsigned int next_extend = STORE_RESULT_PREALLOCATED_SET_IF_NOT_EMPTY, free_rows;
MYSQLND_RES_BG_BUFFERED *set = result->bg_stored_data;
MYSQLND *conn = result->conn;
DBG_ENTER("mysqlnd_background_store_result_fetch_data");
free_rows = next_extend;
/* persistent */
PACKET_INIT(row_packet, PROT_ROW_PACKET, php_mysql_packet_row *, TRUE);
row_packet->result_set_memory_pool = result->result_set_memory_pool;
row_packet->field_count = result->meta->field_count;
row_packet->binary_protocol = result->m.row_decoder == php_mysqlnd_rowp_read_binary_protocol;
row_packet->fields_metadata = result->meta->fields;
row_packet->bit_fields_count = result->meta->bit_fields_count;
row_packet->bit_fields_total_len= result->meta->bit_fields_total_len;
row_packet->persistent_alloc = TRUE;
while (FAIL != (ret = PACKET_READ(row_packet, conn)) && !row_packet->eof) {
tsrm_mutex_lock(set->LOCK);
if (!free_rows) {
uint64_t total_rows = free_rows = next_extend = next_extend * 5 / 3; /* extend with 33% */
uint64_t old_size;
total_rows += set->row_count;
old_size = set->data_size;
set->data_size = total_rows;
set->data = mnd_perealloc(set->data, set->data_size * sizeof(zval **), set->persistent);
#if 0
memset(set->data + old_size, 0, (set->data_size - old_size) * sizeof(zval **));
#endif
set->row_buffers = mnd_perealloc(set->row_buffers,
total_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *),
set->persistent);
}
set->row_buffers[set->row_count] = row_packet->row_buffer;
set->data[set->row_count] = row_packet->fields;
if (set->decode_in_foreground == FALSE) {
unsigned int i;
result->m.row_decoder(set->row_buffers[set->row_count],
set->data[set->row_count],
result->meta->field_count,
result->meta->fields,
result->conn->options.numeric_and_datetime_as_unicode,
result->conn->options.int_and_float_native,
result->conn->zval_cache,
&result->conn->stats TSRMLS_CC);
for (i = 0; i < result->field_count; i++) {
/*
NULL fields are 0 length, 0 is not more than 0
String of zero size, definitely can't be the next max_length.
Thus for NULL and zero-length we are quite efficient.
*/
if (Z_TYPE_P(set->data[set->row_count][i]) >= IS_STRING) {
unsigned long len = Z_STRLEN_P(set->data[set->row_count][i]);
if (result->meta->fields[i].max_length < len) {
result->meta->fields[i].max_length = len;
}
}
}
}
set->row_count++;
tsrm_mutex_unlock(set->LOCK);
free_rows--;
/* So row_packet's destructor function won't efree() it */
row_packet->row_buffer = NULL;
row_packet->fields = NULL;
/*
No need to FREE_ALLOCA as we can reuse the
'lengths' and 'fields' arrays. For lengths its absolutely safe.
'fields' is reused because the ownership of the strings has been
transfered above.
*/
}
#if 0
MYSQLND_INC_CONN_STATISTIC_W_VALUE(&conn->stats,
binary_protocol? STAT_ROWS_BUFFERED_FROM_CLIENT_PS:
STAT_ROWS_BUFFERED_FROM_CLIENT_NORMAL,
set->row_count);
#endif
tsrm_mutex_lock(set->LOCK);
/* Finally clean */
if (row_packet->eof) {
set->upsert_status.warning_count = row_packet->warning_count;
set->upsert_status.server_status = row_packet->server_status;
}
/* save some memory */
if (free_rows) {
set->data_size = set->row_count;
set->data = mnd_perealloc(set->data,
(size_t) set->data_size * sizeof(zval **), set->persistent);
set->row_buffers = mnd_perealloc(set->row_buffers,
set->row_count * sizeof(MYSQLND_MEMORY_POOL_CHUNK *),
set->persistent);
}
if (ret == FAIL) {
set->error_info = row_packet->error_info;
} else {
/* Position at the first row */
set->data_cursor = set->data;
/* libmysql's documentation says it should be so for SELECT statements */
conn->upsert_status.affected_rows = set->row_count;
set->upsert_status.affected_rows = set->row_count;
}
set->bg_fetch_finished = TRUE;
tsrm_mutex_unlock(set->LOCK);
PACKET_FREE(row_packet);
if (conn->upsert_status.server_status & SERVER_MORE_RESULTS_EXISTS) {
CONN_SET_STATE(conn, CONN_NEXT_RESULT_PENDING);
} else {
CONN_SET_STATE(conn, CONN_READY);
}
DBG_INF_FMT("ret=%s row_count=%u warnings=%u server_status=%u", ret == PASS? "PASS":"FAIL",
set->row_count, conn->upsert_status.warning_count, conn->upsert_status.server_status);
DBG_RETURN(ret);
}
/* }}} */
#endif
/* {{{ mysqlnd_res::background_store_result */
static MYSQLND_RES *
MYSQLND_METHOD(mysqlnd_res, background_store_result)(MYSQLND_RES * result, MYSQLND * const conn, zend_bool ps TSRMLS_DC)
{
#ifndef MYSQLND_THREADED
return (result->m.store_result(result, conn, ps TSRMLS_CC));
#else
enum_func_status ret;
zend_bool to_cache = TRUE;
DBG_ENTER("mysqlnd_res::background_store_result");
DBG_INF_FMT("conn=%d ps_protocol=%d", conn->thread_id, ps);
/* We need the conn because we are doing lazy zval initialization in buffered_fetch_row */
result->conn = conn->m->get_reference(conn TSRMLS_CC);
result->type = MYSQLND_RES_NORMAL;
result->m.fetch_row = mysqlnd_fetch_row_async_buffered;
result->m.fetch_lengths = mysqlnd_fetch_lengths_async_buffered;
result->bg_stored_data = mnd_pecalloc(1, sizeof(MYSQLND_RES_BG_BUFFERED), to_cache);
result->bg_stored_data->data_size = STORE_RESULT_PREALLOCATED_SET_IF_NOT_EMPTY;
result->bg_stored_data->data = mnd_pecalloc(result->bg_stored_data->data_size, sizeof(zval **), to_cache);
result->bg_stored_data->row_buffers = mnd_pemalloc(STORE_RESULT_PREALLOCATED_SET_IF_NOT_EMPTY * sizeof(MYSQLND_MEMORY_POOL_CHUNK *), to_cache);
result->bg_stored_data->persistent = to_cache;
result->bg_stored_data->qcache = to_cache? mysqlnd_qcache_get_cache_reference(conn->qcache):NULL;
result->bg_stored_data->references = 1;
result->bg_stored_data->LOCK = tsrm_mutex_alloc();
result->m.row_decoder = ps? php_mysqlnd_rowp_read_binary_protocol:
php_mysqlnd_rowp_read_text_protocol;
CONN_SET_STATE(conn, CONN_FETCHING_DATA);
/*
This should be definitely TRUE. Decoding in background means creating zvals
which is not very safe for Zend MM, will complain in debug mode and more problems
also manifest themselves - unstable.
*/
result->bg_stored_data->decode_in_foreground = TRUE;
result->lengths = mnd_ecalloc(result->field_count, sizeof(unsigned long));
pthread_mutex_lock(&conn->LOCK_work);
pthread_cond_signal(&conn->COND_work);
do {
pthread_cond_wait(&conn->COND_work, &conn->LOCK_work);
} while (conn->current_result); /* this is our invariant */
pthread_mutex_unlock(&conn->LOCK_work);
#if 0
ret = mysqlnd_background_store_result_fetch_data(result TSRMLS_CC);
#endif
DBG_RETURN(result);
#endif
}
/* }}} */
/* {{{ mysqlnd_res::skip_result */
static enum_func_status
MYSQLND_METHOD(mysqlnd_res, skip_result)(MYSQLND_RES * const result TSRMLS_DC)
@@ -2017,20 +1531,18 @@ MYSQLND_METHOD(mysqlnd_res, fetch_field_data)(MYSQLND_RES *result, unsigned int
/* {{{ mysqlnd_result_init */
MYSQLND_RES *mysqlnd_result_init(unsigned int field_count, MYSQLND_THD_ZVAL_PCACHE *cache TSRMLS_DC)
MYSQLND_RES *mysqlnd_result_init(unsigned int field_count TSRMLS_DC)
{
size_t alloc_size = sizeof(MYSQLND_RES) + mysqlnd_plugin_count() * sizeof(void *);
MYSQLND_RES *ret = mnd_ecalloc(1, alloc_size);
DBG_ENTER("mysqlnd_result_init");
DBG_INF_FMT("field_count=%u cache=%p", field_count, cache);
DBG_INF_FMT("field_count=%u", field_count);
ret->field_count = field_count;
ret->zval_cache = cache;
ret->m.use_result = MYSQLND_METHOD(mysqlnd_res, use_result);
ret->m.store_result = MYSQLND_METHOD(mysqlnd_res, store_result);
ret->m.background_store_result = MYSQLND_METHOD(mysqlnd_res, background_store_result);
ret->m.free_result = MYSQLND_METHOD(mysqlnd_res, free_result);
ret->m.seek_data = MYSQLND_METHOD(mysqlnd_res, data_seek);
ret->m.num_rows = MYSQLND_METHOD(mysqlnd_res, num_rows);
@@ -2073,7 +1585,7 @@ PHPAPI void ** _mysqlnd_plugin_get_plugin_result_data(const MYSQLND_RES * result
if (!result || plugin_id >= mysqlnd_plugin_count()) {
return NULL;
}
DBG_RETURN((void *)(result + sizeof(MYSQLND_RES) + plugin_id * sizeof(void *)));
DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES) + plugin_id * sizeof(void *)));
}
/* }}} */
+1 -6
View File
@@ -23,15 +23,10 @@
#ifndef MYSQLND_RESULT_H
#define MYSQLND_RESULT_H
MYSQLND_RES *mysqlnd_result_init(unsigned int field_count, MYSQLND_THD_ZVAL_PCACHE *cache TSRMLS_DC);
MYSQLND_RES *mysqlnd_result_init(unsigned int field_count TSRMLS_DC);
enum_func_status mysqlnd_query_read_result_set_header(MYSQLND *conn, MYSQLND_STMT *stmt TSRMLS_DC);
#ifdef MYSQLND_THREADED
void * mysqlnd_fetch_thread(void *arg);
#endif
enum_func_status mysqlnd_background_store_result_fetch_data(MYSQLND_RES *result TSRMLS_DC);
#endif /* MYSQLND_RESULT_H */
/*
+54 -92
View File
@@ -107,11 +107,6 @@ typedef struct st_mysqlnd_error_info
} mysqlnd_error_info;
typedef struct st_mysqlnd_zval_pcache MYSQLND_ZVAL_PCACHE;
typedef struct st_mysqlnd_thread_zval_pcache MYSQLND_THD_ZVAL_PCACHE;
typedef struct st_mysqlnd_qcache MYSQLND_QCACHE;
typedef struct st_mysqlnd_infile_info
{
php_stream *fd;
@@ -146,13 +141,8 @@ typedef struct st_mysqlnd_infile
void *userdata;
} MYSQLND_INFILE;
typedef struct st_mysqlnd_option
typedef struct st_mysqlnd_options
{
/* timeouts */
unsigned int timeout_connect;
unsigned int timeout_read;
unsigned int timeout_write;
ulong flags;
/* init commands - we need to send them to server directly after connect */
@@ -179,11 +169,21 @@ typedef struct st_mysqlnd_option
#ifdef MYSQLND_STRING_TO_INT_CONVERSION
zend_bool int_and_float_native;
#endif
} MYSQLND_OPTIONS;
typedef struct st_mysqlnd_net_options
{
/* timeouts */
unsigned int timeout_connect;
unsigned int timeout_read;
unsigned int timeout_write;
unsigned int net_read_buffer_size;
} MYSQLND_OPTION;
} MYSQLND_NET_OPTIONS;
typedef struct st_mysqlnd_connection MYSQLND;
typedef struct st_mysqlnd_net MYSQLND_NET;
typedef struct st_mysqlnd_res MYSQLND_RES;
typedef char** MYSQLND_ROW_C; /* return data as array of strings */
typedef struct st_mysqlnd_stmt MYSQLND_STMT;
@@ -195,7 +195,6 @@ typedef struct st_mysqlnd_result_bind MYSQLND_RESULT_BIND;
typedef struct st_mysqlnd_result_metadata MYSQLND_RES_METADATA;
typedef struct st_mysqlnd_buffered_result MYSQLND_RES_BUFFERED;
typedef struct st_mysqlnd_background_buffered_result MYSQLND_RES_BG_BUFFERED;
typedef struct st_mysqlnd_unbuffered_result MYSQLND_RES_UNBUFFERED;
typedef struct st_mysqlnd_debug MYSQLND_DEBUG;
@@ -229,32 +228,24 @@ typedef struct st_mysqlnd_read_buffer {
} MYSQLND_READ_BUFFER;
typedef struct st_mysqlnd_net
struct st_mysqlnd_net_methods
{
php_stream *stream;
enum_func_status (*stream_read)(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC);
size_t (*stream_write)(MYSQLND * const conn, const zend_uchar * const buf, size_t count TSRMLS_DC);
/* sequence for simple checking of correct packets */
zend_uchar packet_no;
zend_bool compressed;
zend_uchar compressed_envelope_packet_no;
#ifdef MYSQLND_COMPRESSION_ENABLED
MYSQLND_READ_BUFFER * uncompressed_data;
#endif
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
zend_uchar last_command;
#endif
/* cmd buffer */
MYSQLND_CMD_BUFFER cmd_buffer;
} MYSQLND_NET;
enum_func_status (*connect)(MYSQLND_NET * net, const char * const scheme, size_t scheme_len, zend_bool persistent, char **errstr, int * errcode TSRMLS_DC);
size_t (*send)(MYSQLND * const conn, char * const buf, size_t count TSRMLS_DC);
size_t (*receive)(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC);
enum_func_status (*set_client_option)(MYSQLND_NET * const net, enum_mysqlnd_option option, const char * const value TSRMLS_DC);
enum_func_status (*network_read)(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC);
size_t (*network_write)(MYSQLND * const conn, const zend_uchar * const buf, size_t count TSRMLS_DC);
enum_func_status (*decode)(zend_uchar * uncompressed_data, size_t uncompressed_data_len, const zend_uchar * const compressed_data, size_t compressed_data_len TSRMLS_DC);
enum_func_status (*encode)(zend_uchar * compress_buffer, size_t compress_buffer_len, const zend_uchar * const uncompressed_data, size_t uncompressed_data_len TSRMLS_DC);
size_t (*consume_uneaten_data)(MYSQLND_NET * const net, enum php_mysqlnd_server_command cmd TSRMLS_DC);
void (*free_contents)(MYSQLND_NET * net TSRMLS_DC);
};
struct st_mysqlnd_conn_methods
{
enum_func_status (*connect)(MYSQLND *conn, const char *host, const char * user, const char * passwd, unsigned int passwd_len, const char * db, unsigned int db_len, unsigned int port, const char * socket, unsigned int mysql_flags, MYSQLND_THD_ZVAL_PCACHE * zval_cache TSRMLS_DC);
enum_func_status (*connect)(MYSQLND *conn, const char *host, const char * user, const char * passwd, unsigned int passwd_len, const char * db, unsigned int db_len, unsigned int port, const char * socket, unsigned int mysql_flags TSRMLS_DC);
ulong (*escape_string)(const MYSQLND * const conn, char *newstr, const char *escapestr, size_t escapestr_len TSRMLS_DC);
enum_func_status (*set_charset)(MYSQLND * const conn, const char * const charset TSRMLS_DC);
enum_func_status (*query)(MYSQLND *conn, const char *query, unsigned int query_len TSRMLS_DC);
@@ -262,7 +253,6 @@ struct st_mysqlnd_conn_methods
enum_func_status (*reap_query)(MYSQLND *conn TSRMLS_DC);
MYSQLND_RES * (*use_result)(MYSQLND * const conn TSRMLS_DC);
MYSQLND_RES * (*store_result)(MYSQLND * const conn TSRMLS_DC);
MYSQLND_RES * (*background_store_result)(MYSQLND * const conn TSRMLS_DC);
enum_func_status (*next_result)(MYSQLND * const conn TSRMLS_DC);
zend_bool (*more_results)(const MYSQLND * const conn TSRMLS_DC);
@@ -312,6 +302,9 @@ struct st_mysqlnd_conn_methods
enum_func_status (*free_reference)(MYSQLND * const conn TSRMLS_DC);
enum mysqlnd_connection_state (*get_state)(MYSQLND * const conn TSRMLS_DC);
void (*set_state)(MYSQLND * const conn, enum mysqlnd_connection_state new_state TSRMLS_DC);
enum_func_status (*simple_command)(MYSQLND *conn, enum php_mysqlnd_server_command command, const char * const arg, size_t arg_len, enum php_mysql_packet_type ok_packet, zend_bool silent, zend_bool ignore_upsert_status TSRMLS_DC);
enum_func_status (*simple_command_handle_response)(MYSQLND *conn, enum php_mysql_packet_type ok_packet, zend_bool silent, enum php_mysqlnd_server_command command, zend_bool ignore_upsert_status TSRMLS_DC);
};
@@ -323,7 +316,6 @@ struct st_mysqlnd_res_methods
MYSQLND_RES * (*use_result)(MYSQLND_RES * const result, zend_bool ps_protocol TSRMLS_DC);
MYSQLND_RES * (*store_result)(MYSQLND_RES * result, MYSQLND * const conn, zend_bool ps TSRMLS_DC);
MYSQLND_RES * (*background_store_result)(MYSQLND_RES * result, MYSQLND * const conn, zend_bool ps TSRMLS_DC);
void (*fetch_into)(MYSQLND_RES *result, unsigned int flags, zval *return_value, enum_mysqlnd_extension ext TSRMLS_DC ZEND_FILE_LINE_DC);
MYSQLND_ROW_C (*fetch_row_c)(MYSQLND_RES *result TSRMLS_DC);
void (*fetch_all)(MYSQLND_RES *result, unsigned int flags, zval *return_value TSRMLS_DC ZEND_FILE_LINE_DC);
@@ -355,10 +347,7 @@ struct st_mysqlnd_res_methods
unsigned int field_count, MYSQLND_FIELD *fields_metadata,
zend_bool persistent,
zend_bool as_unicode, zend_bool as_int_or_float,
MYSQLND_THD_ZVAL_PCACHE * zval_cache,
MYSQLND_STATS * stats TSRMLS_DC);
};
@@ -380,7 +369,6 @@ struct st_mysqlnd_stmt_methods
enum_func_status (*execute)(MYSQLND_STMT * const stmt TSRMLS_DC);
MYSQLND_RES * (*use_result)(MYSQLND_STMT * const stmt TSRMLS_DC);
MYSQLND_RES * (*store_result)(MYSQLND_STMT * const stmt TSRMLS_DC);
MYSQLND_RES * (*background_store_result)(MYSQLND_STMT * const stmt TSRMLS_DC);
MYSQLND_RES * (*get_result)(MYSQLND_STMT * const stmt TSRMLS_DC);
zend_bool (*more_results)(const MYSQLND_STMT * const stmt TSRMLS_DC);
enum_func_status (*next_result)(MYSQLND_STMT * const stmt TSRMLS_DC);
@@ -421,10 +409,34 @@ struct st_mysqlnd_stmt_methods
};
struct st_mysqlnd_net
{
php_stream *stream;
struct st_mysqlnd_net_methods m;
/* sequence for simple checking of correct packets */
zend_uchar packet_no;
zend_bool compressed;
zend_uchar compressed_envelope_packet_no;
#ifdef MYSQLND_COMPRESSION_ENABLED
MYSQLND_READ_BUFFER * uncompressed_data;
#endif
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
zend_uchar last_command;
#endif
/* cmd buffer */
MYSQLND_CMD_BUFFER cmd_buffer;
MYSQLND_NET_OPTIONS options;
zend_bool persistent;
};
struct st_mysqlnd_connection
{
/* Operation related */
MYSQLND_NET net;
MYSQLND_NET * net;
/* Information related */
char *host;
@@ -485,31 +497,11 @@ struct st_mysqlnd_connection
zend_bool persistent;
/* options */
MYSQLND_OPTION options;
/* zval cache */
MYSQLND_THD_ZVAL_PCACHE *zval_cache;
/* qcache */
MYSQLND_QCACHE *qcache;
MYSQLND_OPTIONS options;
/* stats */
MYSQLND_STATS stats;
#ifdef MYSQLND_THREADED
MUTEX_T LOCK_state;
pthread_cond_t COND_work_done;
pthread_mutex_t LOCK_work;
pthread_cond_t COND_work;
pthread_cond_t COND_thread_ended;
zend_bool thread_is_running;
zend_bool thread_killed;
void *** tsrm_ls;
#endif
struct st_mysqlnd_conn_methods *m;
};
@@ -541,31 +533,6 @@ struct st_mysqlnd_result_metadata
};
struct st_mysqlnd_background_buffered_result
{
zval ***data;
uint64_t data_size;
zval ***data_cursor;
MYSQLND_MEMORY_POOL_CHUNK **row_buffers;
uint64_t row_count;
uint64_t initialized_rows;
zend_bool persistent;
MYSQLND_QCACHE *qcache;
unsigned int references;
zend_bool decode_in_foreground;
#ifdef ZTS
zend_bool bg_fetch_finished;
MUTEX_T LOCK;
#endif
mysqlnd_error_info error_info;
mysqlnd_upsert_status upsert_status;
};
struct st_mysqlnd_buffered_result
{
zval **data;
@@ -575,7 +542,6 @@ struct st_mysqlnd_buffered_result
uint64_t initialized_rows;
zend_bool persistent;
MYSQLND_QCACHE *qcache;
unsigned int references;
mysqlnd_error_info error_info;
@@ -606,7 +572,6 @@ struct st_mysqlnd_res
/* To be used with store_result() - both normal and PS */
MYSQLND_RES_BUFFERED *stored_data;
MYSQLND_RES_BG_BUFFERED *bg_stored_data;
MYSQLND_RES_UNBUFFERED *unbuf;
/*
@@ -617,9 +582,6 @@ struct st_mysqlnd_res
php_mysql_packet_row *row_packet;
/* zval cache */
MYSQLND_THD_ZVAL_PCACHE *zval_cache;
MYSQLND_MEMORY_POOL * result_set_memory_pool;
};
+47 -609
View File
@@ -1,4 +1,3 @@
/*
+----------------------------------------------------------------------+
| PHP Version 6 |
@@ -24,27 +23,15 @@
#include "mysqlnd_priv.h"
#include "mysqlnd_wireprotocol.h"
#include "mysqlnd_statistics.h"
#include "mysqlnd_palloc.h"
#include "mysqlnd_debug.h"
#include "mysqlnd_block_alloc.h"
#include "ext/standard/sha1.h"
#include "php_network.h"
#include "zend_ini.h"
#ifdef MYSQLND_COMPRESSION_ENABLED
#include <zlib.h>
#endif
#ifndef PHP_WIN32
#include <netinet/tcp.h>
#else
#include <winsock.h>
#endif
#define MYSQLND_SILENT 1
#define MYSQLND_DUMP_HEADER_N_BODY
#define PACKET_READ_HEADER_AND_BODY(packet, conn, buf, buf_size, packet_type_as_text, packet_type) \
{ \
DBG_INF_FMT("buf=%p size=%u", (buf), (buf_size)); \
@@ -60,7 +47,7 @@
(buf_size), (packet)->header.size, (packet)->header.size - (buf_size)); \
DBG_RETURN(FAIL); \
}\
if (FAIL == mysqlnd_read_body((conn), &((packet)->header), (buf) TSRMLS_CC)) { \
if (FAIL == conn->net->m.receive((conn), (buf), (packet)->header.size TSRMLS_CC)) { \
CONN_SET_STATE(conn, CONN_QUIT_SENT); \
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);\
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysqlnd_server_gone); \
@@ -85,6 +72,9 @@ char * mysqlnd_read_header_name = "mysqlnd_read_header";
char * mysqlnd_read_body_name = "mysqlnd_read_body";
#define ERROR_MARKER 0xFF
#define EODATA_MARKER 0xFE
/* {{{ mysqlnd_command_to_text
*/
const char * const mysqlnd_command_to_text[COM_END] =
@@ -214,120 +204,6 @@ zend_uchar *php_mysqlnd_net_store_length(zend_uchar *packet, uint64_t length)
/* }}} */
#ifdef MYSQLND_COMPRESSION_ENABLED
/* {{{ php_mysqlnd_read_buffer_is_empty */
static zend_bool
php_mysqlnd_read_buffer_is_empty(MYSQLND_READ_BUFFER * buffer)
{
return buffer->len? FALSE:TRUE;
}
/* }}} */
/* {{{ php_mysqlnd_read_buffer_read */
static void
php_mysqlnd_read_buffer_read(MYSQLND_READ_BUFFER * buffer, size_t count, zend_uchar * dest)
{
if (buffer->len >= count) {
memcpy(dest, buffer->data + buffer->offset, count);
buffer->offset += count;
buffer->len -= count;
}
}
/* }}} */
/* {{{ php_mysqlnd_read_buffer_bytes_left */
static size_t
php_mysqlnd_read_buffer_bytes_left(MYSQLND_READ_BUFFER * buffer)
{
return buffer->len;
}
/* }}} */
/* {{{ php_mysqlnd_read_buffer_free */
static void
php_mysqlnd_read_buffer_free(MYSQLND_READ_BUFFER ** buffer TSRMLS_DC)
{
DBG_ENTER("php_mysqlnd_read_buffer_free");
if (*buffer) {
mnd_efree((*buffer)->data);
mnd_efree(*buffer);
*buffer = NULL;
}
DBG_VOID_RETURN;
}
/* }}} */
/* {{{ php_mysqlnd_create_read_buffer */
static MYSQLND_READ_BUFFER *
mysqlnd_create_read_buffer(size_t count TSRMLS_DC)
{
MYSQLND_READ_BUFFER * ret = mnd_emalloc(sizeof(MYSQLND_READ_BUFFER));
DBG_ENTER("mysqlnd_create_read_buffer");
ret->is_empty = php_mysqlnd_read_buffer_is_empty;
ret->read = php_mysqlnd_read_buffer_read;
ret->bytes_left = php_mysqlnd_read_buffer_bytes_left;
ret->free_buffer = php_mysqlnd_read_buffer_free;
ret->data = mnd_emalloc(count);
ret->size = ret->len = count;
ret->offset = 0;
DBG_RETURN(ret);
}
/* }}} */
#endif
/* {{{ php_mysqlnd_consume_uneaten_data */
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
size_t php_mysqlnd_consume_uneaten_data(MYSQLND * const conn, enum php_mysqlnd_server_command cmd TSRMLS_DC)
{
/*
Switch to non-blocking mode and try to consume something from
the line, if possible, then continue. This saves us from looking for
the actuall place where out-of-order packets have been sent.
If someone is completely sure that everything is fine, he can switch it
off.
*/
char tmp_buf[256];
MYSQLND_NET *net = &conn->net;
size_t skipped_bytes = 0;
int opt = PHP_STREAM_OPTION_BLOCKING;
int was_blocked = net->stream->ops->set_option(net->stream, opt, 0, NULL TSRMLS_CC);
DBG_ENTER("php_mysqlnd_consume_uneaten_data");
if (PHP_STREAM_OPTION_RETURN_ERR != was_blocked) {
/* Do a read of 1 byte */
int bytes_consumed;
do {
skipped_bytes += (bytes_consumed = php_stream_read(net->stream, tmp_buf, sizeof(tmp_buf)));
} while (bytes_consumed == sizeof(tmp_buf));
if (was_blocked) {
net->stream->ops->set_option(net->stream, opt, 1, NULL TSRMLS_CC);
}
if (bytes_consumed) {
DBG_ERR_FMT("Skipped %u bytes. Last command %s hasn't consumed all the output from the server",
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Skipped %u bytes. Last command %s hasn't "
"consumed all the output from the server",
bytes_consumed, mysqlnd_command_to_text[net->last_command]);
}
}
net->last_command = cmd;
DBG_RETURN(skipped_bytes);
}
#endif
/* }}} */
/* {{{ php_mysqlnd_read_error_from_line */
static enum_func_status
php_mysqlnd_read_error_from_line(zend_uchar *buf, size_t buf_len,
@@ -362,381 +238,16 @@ php_mysqlnd_read_error_from_line(zend_uchar *buf, size_t buf_len,
/* }}} */
/* {{{ mysqlnd_set_sock_no_delay */
int mysqlnd_set_sock_no_delay(php_stream *stream)
{
int socketd = ((php_netstream_data_t*)stream->abstract)->socket;
int ret = SUCCESS;
int flag = 1;
int result = setsockopt(socketd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
TSRMLS_FETCH();
DBG_ENTER("mysqlnd_set_sock_no_delay");
if (result == -1) {
ret = FAILURE;
}
DBG_RETURN(ret);
}
/* }}} */
/* {{{ mysqlnd_stream_write */
size_t mysqlnd_stream_write(MYSQLND * const conn, const zend_uchar * const buf, size_t count TSRMLS_DC)
{
size_t ret;
DBG_ENTER("mysqlnd_stream_write");
ret = php_stream_write(conn->net.stream, (char *)buf, count);
DBG_RETURN(ret);
}
/* }}} */
/* We assume that MYSQLND_HEADER_SIZE is 4 bytes !! */
#define STORE_HEADER_SIZE(safe_storage, buffer) int4store((safe_storage), (*(uint32_t *)(buffer)))
#define RESTORE_HEADER_SIZE(buffer, safe_storage) STORE_HEADER_SIZE((safe_storage), (buffer))
/* {{{ mysqlnd_stream_write_w_header */
/*
IMPORTANT : It's expected that buf has place in the beginning for MYSQLND_HEADER_SIZE !!!!
This is done for performance reasons in the caller of this function.
Otherwise we will have to do send two TCP packets, or do new alloc and memcpy.
Neither are quick, thus the clients of this function are obligated to do
what they are asked for.
`count` is actually the length of the payload data. Thus :
count + MYSQLND_HEADER_SIZE = sizeof(buf) (not the pointer but the actual buffer)
*/
size_t mysqlnd_stream_write_w_header(MYSQLND * const conn, char * const buf, size_t count TSRMLS_DC)
{
zend_uchar safe_buf[((MYSQLND_HEADER_SIZE) + (sizeof(zend_uchar)) - 1) / (sizeof(zend_uchar))];
zend_uchar *safe_storage = safe_buf;
MYSQLND_NET *net = &conn->net;
size_t old_chunk_size = net->stream->chunk_size;
size_t ret, left = count, packets_sent = 1;
zend_uchar *p = (zend_uchar *) buf;
zend_uchar * compress_buf = NULL;
size_t comp_buf_size = 0;
DBG_ENTER("mysqlnd_stream_write_w_header");
DBG_INF_FMT("conn=%llu count=%lu compression=%d", conn->thread_id, count, net->compressed);
net->stream->chunk_size = MYSQLND_MAX_PACKET_SIZE;
if (net->compressed == TRUE) {
comp_buf_size = MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE + MIN(left, MYSQLND_MAX_PACKET_SIZE);
DBG_INF_FMT("compress_buf_size=%d", comp_buf_size);
compress_buf = emalloc(comp_buf_size);
}
while (left > MYSQLND_MAX_PACKET_SIZE) {
#ifdef MYSQLND_COMPRESSION_ENABLED
if (net->compressed == TRUE) {
/* here we need to compress the data and then write it, first comes the compressed header */
uLong tmp_complen = MYSQLND_MAX_PACKET_SIZE;
size_t payload_size;
zend_uchar * uncompressed_payload = p; /* should include the header */
int res;
STORE_HEADER_SIZE(safe_storage, uncompressed_payload);
int3store(uncompressed_payload, MYSQLND_MAX_PACKET_SIZE);
int1store(uncompressed_payload + 3, net->packet_no);
DBG_INF_FMT("compress(%p, %p, %p, %d)", (compress_buf + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE), &tmp_complen, p, MYSQLND_MAX_PACKET_SIZE + MYSQLND_HEADER_SIZE);
res = compress((compress_buf + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE), &tmp_complen, uncompressed_payload, MYSQLND_MAX_PACKET_SIZE + MYSQLND_HEADER_SIZE);
if (res == Z_OK) {
DBG_INF_FMT("compression successful. compressed size=%d", tmp_complen);
int3store(compress_buf + MYSQLND_HEADER_SIZE, MYSQLND_MAX_PACKET_SIZE + MYSQLND_HEADER_SIZE);
payload_size = tmp_complen;
} else {
DBG_INF_FMT("compression NOT successful. error=%d Z_OK=%d Z_BUF_ERROR=%d Z_MEM_ERROR=%d", res, Z_OK, Z_BUF_ERROR, Z_MEM_ERROR);
int3store(compress_buf + MYSQLND_HEADER_SIZE, 0);
memcpy(compress_buf + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE, uncompressed_payload, MYSQLND_MAX_PACKET_SIZE + MYSQLND_HEADER_SIZE);
payload_size = MYSQLND_MAX_PACKET_SIZE + MYSQLND_HEADER_SIZE;
}
RESTORE_HEADER_SIZE(uncompressed_payload, safe_storage);
int3store(compress_buf, payload_size);
int1store(compress_buf + 3, net->packet_no);
DBG_INF_FMT("writing %d bytes to the network", payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE);
ret = conn->net.stream_write(conn, compress_buf, payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE TSRMLS_CC);
net->compressed_envelope_packet_no++;
} else
#endif /* MYSQLND_COMPRESSION_ENABLED */
{
DBG_INF("no compression");
STORE_HEADER_SIZE(safe_storage, p);
int3store(p, MYSQLND_MAX_PACKET_SIZE);
int1store(p + 3, net->packet_no);
ret = conn->net.stream_write(conn, p, MYSQLND_MAX_PACKET_SIZE + MYSQLND_HEADER_SIZE TSRMLS_CC);
RESTORE_HEADER_SIZE(p, safe_storage);
net->compressed_envelope_packet_no++;
}
net->packet_no++;
p += MYSQLND_MAX_PACKET_SIZE;
left -= MYSQLND_MAX_PACKET_SIZE;
packets_sent++;
}
DBG_INF_FMT("packet_size=%d packet_no=%d", left, net->packet_no);
/* Even for zero size payload we have to send a packet */
#ifdef MYSQLND_COMPRESSION_ENABLED
if (net->compressed == TRUE) {
/* here we need to compress the data and then write it, first comes the compressed header */
uLong tmp_complen = left;
size_t payload_size;
zend_uchar * uncompressed_payload = p; /* should include the header */
int res = Z_BUF_ERROR;
STORE_HEADER_SIZE(safe_storage, uncompressed_payload);
int3store(uncompressed_payload, left);
int1store(uncompressed_payload + 3, net->packet_no);
if ((left + MYSQLND_HEADER_SIZE) > MYSQLND_MIN_COMPRESS_LEN) {
DBG_INF_FMT("compress(%p, %p, %p, %d)", (compress_buf + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE), &tmp_complen, p, left + MYSQLND_HEADER_SIZE);
res = compress((compress_buf + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE), &tmp_complen, uncompressed_payload, left + MYSQLND_HEADER_SIZE);
if (res == Z_OK) {
DBG_INF_FMT("compression successful. compressed size=%d", tmp_complen);
int3store(compress_buf + MYSQLND_HEADER_SIZE, left + MYSQLND_HEADER_SIZE);
payload_size = tmp_complen;
}
} else {
DBG_INF("Too short for compression");
}
if (res != Z_OK) {
DBG_INF_FMT("compression NOT successful. error=%d Z_OK=%d Z_BUF_ERROR=%d Z_MEM_ERROR=%d", res, Z_OK, Z_BUF_ERROR, Z_MEM_ERROR);
int3store(compress_buf + MYSQLND_HEADER_SIZE, 0);
memcpy(compress_buf + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE, uncompressed_payload, left + MYSQLND_HEADER_SIZE);
payload_size = left + MYSQLND_HEADER_SIZE;
}
RESTORE_HEADER_SIZE(uncompressed_payload, safe_storage);
int3store(compress_buf, payload_size);
int1store(compress_buf + 3, net->packet_no);
DBG_INF_FMT("writing %d bytes to the network", payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE);
ret = conn->net.stream_write(conn, compress_buf, payload_size + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE TSRMLS_CC);
net->compressed_envelope_packet_no++;
#if WHEN_WE_NEED_TO_CHECK_WHETHER_COMPRESSION_WORKS_CORRECTLY
if (res == Z_OK) {
size_t decompressed_size = left + MYSQLND_HEADER_SIZE;
uLongf tmp_complen2 = decompressed_size;
zend_uchar * decompressed_data = malloc(decompressed_size);
int error = uncompress(decompressed_data, &tmp_complen2, compress_buf + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE, payload_size);
if (error == Z_OK) {
int i;
DBG_INF("success decompressing");
for (i = 0 ; i < decompressed_size; i++) {
if (i && (i % 30 == 0)) {
printf("\n\t\t");
}
printf("%.2X ", (int)*((char*)&(decompressed_data[i])));
DBG_INF_FMT("%.2X ", (int)*((char*)&(decompressed_data[i])));
}
} else {
DBG_INF("error decompressing");
}
free(decompressed_data);
}
#endif /* WHEN_WE_NEED_TO_CHECK_WHETHER_COMPRESSION_WORKS_CORRECTLY */
} else
#endif /* MYSQLND_COMPRESSION_ENABLED */
{
DBG_INF("no compression");
STORE_HEADER_SIZE(safe_storage, p);
int3store(p, left);
int1store(p + 3, net->packet_no);
ret = conn->net.stream_write(conn, p, left + MYSQLND_HEADER_SIZE TSRMLS_CC);
RESTORE_HEADER_SIZE(p, safe_storage);
}
net->packet_no++;
if (!ret) {
DBG_ERR_FMT("Can't %u send bytes", count);
conn->state = CONN_QUIT_SENT;
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
}
MYSQLND_INC_CONN_STATISTIC_W_VALUE3(&conn->stats,
STAT_BYTES_SENT, count + packets_sent * MYSQLND_HEADER_SIZE,
STAT_PROTOCOL_OVERHEAD_OUT, packets_sent * MYSQLND_HEADER_SIZE,
STAT_PACKETS_SENT, packets_sent);
net->stream->chunk_size = old_chunk_size;
if (compress_buf) {
efree(compress_buf);
}
DBG_RETURN(ret);
}
/* }}} */
/* {{{ mysqlnd_read_from_stream */
enum_func_status
mysqlnd_read_from_stream(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC)
{
size_t to_read = count, ret;
size_t old_chunk_size = conn->net.stream->chunk_size;
DBG_ENTER("mysqlnd_read_from_stream");
DBG_INF_FMT("count=%u", count);
conn->net.stream->chunk_size = MIN(to_read, conn->options.net_read_buffer_size);
while (to_read) {
if (!(ret = php_stream_read(conn->net.stream, (char *) buffer, to_read))) {
DBG_ERR_FMT("Error while reading header from socket");
DBG_RETURN(FAIL);
}
buffer += ret;
to_read -= ret;
}
MYSQLND_INC_CONN_STATISTIC_W_VALUE(&conn->stats, STAT_BYTES_RECEIVED, count);
conn->net.stream->chunk_size = old_chunk_size;
DBG_RETURN(PASS);
}
/* }}} */
#ifdef MYSQLND_COMPRESSION_ENABLED
/* {{{ mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer */
static enum_func_status
mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer(MYSQLND * conn, size_t net_payload_size TSRMLS_DC)
{
MYSQLND_NET * net = &conn->net;
size_t decompressed_size;
enum_func_status ret = PASS;
zend_uchar * compressed_data = NULL;
zend_uchar comp_header[COMPRESSED_HEADER_SIZE];
DBG_ENTER("mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer");
/* Read the compressed header */
if (FAIL == conn->net.stream_read(conn, comp_header, COMPRESSED_HEADER_SIZE TSRMLS_CC)) {
DBG_RETURN(FAIL);
}
decompressed_size = uint3korr(comp_header);
/* When decompressed_size is 0, then the data is not compressed, and we have wasted 3 bytes */
/* we need to decompress the data */
if (decompressed_size) {
int error;
uLongf tmp_complen = decompressed_size;
compressed_data = emalloc(net_payload_size);
if (FAIL == conn->net.stream_read(conn, compressed_data, net_payload_size TSRMLS_CC)) {
ret = FAIL;
goto end;
}
net->uncompressed_data = mysqlnd_create_read_buffer(decompressed_size TSRMLS_CC);
error = uncompress(net->uncompressed_data->data, &tmp_complen, compressed_data, net_payload_size);
DBG_INF_FMT("compressed data: decomp_len=%d compressed_size=%d", decompressed_size, net_payload_size);
if (error != Z_OK) {
DBG_ERR_FMT("Can't uncompress packet, error: %d", error);
ret = FAIL;
goto end;
}
} else {
DBG_INF_FMT("The server decided not to compress the data. Our job is easy. Copying %u bytes", net_payload_size);
net->uncompressed_data = mysqlnd_create_read_buffer(net_payload_size TSRMLS_CC);
if (FAIL == conn->net.stream_read(conn, net->uncompressed_data->data, net_payload_size TSRMLS_CC)) {
ret = FAIL;
goto end;
}
}
end:
if (compressed_data) {
efree(compressed_data);
}
DBG_RETURN(ret);
}
#endif /* MYSQLND_COMPRESSION_ENABLED */
/* {{{ mysqlnd_real_read */
static enum_func_status
mysqlnd_real_read(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC)
{
size_t to_read = count;
zend_uchar * p = buffer;
DBG_ENTER("mysqlnd_real_read");
#ifdef MYSQLND_COMPRESSION_ENABLED
if (conn->net.compressed) {
MYSQLND_NET * net = &conn->net;
if (net->uncompressed_data) {
size_t to_read_from_buffer = MIN(net->uncompressed_data->bytes_left(net->uncompressed_data), to_read);
DBG_INF_FMT("reading %u from uncompressed_data buffer", to_read_from_buffer);
if (to_read_from_buffer) {
net->uncompressed_data->read(net->uncompressed_data, to_read_from_buffer, (zend_uchar *) p);
p += to_read_from_buffer;
to_read -= to_read_from_buffer;
}
DBG_INF_FMT("left %u to read", to_read);
if (TRUE == net->uncompressed_data->is_empty(net->uncompressed_data)) {
/* Everything was consumed. This should never happen here, but for security */
net->uncompressed_data->free_buffer(&net->uncompressed_data TSRMLS_CC);
}
}
if (to_read) {
zend_uchar net_header[MYSQLND_HEADER_SIZE];
size_t net_payload_size;
zend_uchar packet_no;
if (FAIL == conn->net.stream_read(conn, net_header, MYSQLND_HEADER_SIZE TSRMLS_CC)) {
DBG_RETURN(FAIL);
}
net_payload_size = uint3korr(net_header);
packet_no = uint1korr(net_header + 3);
if (net->compressed_envelope_packet_no != packet_no) {
DBG_ERR_FMT("Transport level: packets out of order. Expected %d received %d. Packet size=%d",
net->compressed_envelope_packet_no, packet_no, net_payload_size);
php_error(E_WARNING, "Packets out of order. Expected %d received %d. Packet size="MYSQLND_SZ_T_SPEC,
net->compressed_envelope_packet_no, packet_no, net_payload_size);
#if 0
*(int *) NULL = 0;
#endif
DBG_RETURN(FAIL);
}
net->compressed_envelope_packet_no++;
#ifdef MYSQLND_DUMP_HEADER_N_BODY
DBG_INF_FMT("HEADER: hwd_packet_no=%d size=%3d", packet_no, net_payload_size);
#endif
/* Now let's read from the wire, decompress it and fill the read buffer */
mysqlnd_read_compressed_packet_from_stream_and_fill_read_buffer(conn, net_payload_size TSRMLS_CC);
/*
Now a bit of recursion - read from the read buffer,
if the data which we have just read from the wire
is not enough, then the recursive call will try to
satisfy it until it is satisfied.
*/
DBG_RETURN(mysqlnd_real_read(conn, p, to_read TSRMLS_CC));
}
DBG_RETURN(PASS);
}
#endif /* MYSQLND_COMPRESSION_ENABLED */
DBG_RETURN(conn->net.stream_read(conn, p, to_read TSRMLS_CC));
}
/* }}} */
/* {{{ mysqlnd_read_header */
static enum_func_status
mysqlnd_read_header(MYSQLND * conn, mysqlnd_packet_header * header TSRMLS_DC)
{
MYSQLND_NET *net = &conn->net;
MYSQLND_NET * net = conn->net;
zend_uchar buffer[MYSQLND_HEADER_SIZE];
DBG_ENTER("mysqlnd_read_header_name");
DBG_INF_FMT("compressed=%d conn_id=%u", net->compressed, conn->thread_id);
if (FAIL == mysqlnd_real_read(conn, buffer, MYSQLND_HEADER_SIZE TSRMLS_CC)) {
if (FAIL == net->m.receive(conn, buffer, MYSQLND_HEADER_SIZE TSRMLS_CC)) {
DBG_RETURN(FAIL);
}
@@ -746,8 +257,7 @@ mysqlnd_read_header(MYSQLND * conn, mysqlnd_packet_header * header TSRMLS_DC)
#ifdef MYSQLND_DUMP_HEADER_N_BODY
DBG_INF_FMT("HEADER: prot_packet_no=%d size=%3d", header->packet_no, header->size);
#endif
MYSQLND_INC_CONN_STATISTIC_W_VALUE3(&conn->stats,
STAT_BYTES_RECEIVED, MYSQLND_HEADER_SIZE,
MYSQLND_INC_CONN_STATISTIC_W_VALUE2(&conn->stats,
STAT_PROTOCOL_OVERHEAD_IN, MYSQLND_HEADER_SIZE,
STAT_PACKETS_RECEIVED, 1);
@@ -771,20 +281,6 @@ mysqlnd_read_header(MYSQLND * conn, mysqlnd_packet_header * header TSRMLS_DC)
/* }}} */
/* {{{ mysqlnd_read_body */
static enum_func_status
mysqlnd_read_body(MYSQLND *conn, mysqlnd_packet_header * header, zend_uchar * store_buf TSRMLS_DC)
{
MYSQLND_NET *net = &conn->net;
DBG_ENTER(mysqlnd_read_body_name);
DBG_INF_FMT("chunk_size=%d compression=%d", net->stream->chunk_size, net->compressed);
DBG_RETURN(mysqlnd_real_read(conn, store_buf, header->size TSRMLS_CC));
}
/* }}} */
/* {{{ php_mysqlnd_greet_read */
static enum_func_status
php_mysqlnd_greet_read(void *_packet, MYSQLND *conn TSRMLS_DC)
@@ -801,7 +297,7 @@ php_mysqlnd_greet_read(void *_packet, MYSQLND *conn TSRMLS_DC)
packet->protocol_version = uint1korr(p);
p++;
if (packet->protocol_version == 0xFF) {
if (ERROR_MARKER == packet->protocol_version) {
php_mysqlnd_read_error_from_line(p, packet->header.size - 1,
packet->error, sizeof(packet->error),
&packet->error_no, packet->sqlstate
@@ -989,7 +485,7 @@ size_t php_mysqlnd_auth_write(void *_packet, MYSQLND *conn TSRMLS_DC)
/* Handle CLIENT_CONNECT_WITH_DB */
/* no \0 for no DB */
DBG_RETURN(mysqlnd_stream_write_w_header(conn, buffer, p - buffer - MYSQLND_HEADER_SIZE TSRMLS_CC));
DBG_RETURN(conn->net->m.send(conn, buffer, p - buffer - MYSQLND_HEADER_SIZE TSRMLS_CC));
}
/* }}} */
@@ -1012,8 +508,8 @@ static enum_func_status
php_mysqlnd_ok_read(void *_packet, MYSQLND *conn TSRMLS_DC)
{
zend_uchar local_buf[OK_BUFFER_SIZE];
size_t buf_len = conn->net.cmd_buffer.buffer? conn->net.cmd_buffer.length : OK_BUFFER_SIZE;
zend_uchar *buf = conn->net.cmd_buffer.buffer? (zend_uchar *) conn->net.cmd_buffer.buffer : local_buf;
size_t buf_len = conn->net->cmd_buffer.buffer? conn->net->cmd_buffer.length : OK_BUFFER_SIZE;
zend_uchar *buf = conn->net->cmd_buffer.buffer? (zend_uchar *) conn->net->cmd_buffer.buffer : local_buf;
zend_uchar *p = buf;
zend_uchar *begin = buf;
unsigned long i;
@@ -1023,11 +519,11 @@ php_mysqlnd_ok_read(void *_packet, MYSQLND *conn TSRMLS_DC)
PACKET_READ_HEADER_AND_BODY(packet, conn, buf, buf_len, "OK", PROT_OK_PACKET);
/* Should be always 0x0 or 0xFF for error */
/* Should be always 0x0 or ERROR_MARKER for error */
packet->field_count = uint1korr(p);
p++;
if (0xFF == packet->field_count) {
if (ERROR_MARKER == packet->field_count) {
php_mysqlnd_read_error_from_line(p, packet->header.size - 1,
packet->error, sizeof(packet->error),
&packet->error_no, packet->sqlstate
@@ -1094,8 +590,8 @@ php_mysqlnd_eof_read(void *_packet, MYSQLND *conn TSRMLS_DC)
Error : error_code + '#' + sqlstate + MYSQLND_ERRMSG_SIZE
*/
php_mysql_packet_eof *packet= (php_mysql_packet_eof *) _packet;
size_t buf_len = conn->net.cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net.cmd_buffer.buffer;
size_t buf_len = conn->net->cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
zend_uchar *p = buf;
zend_uchar *begin = buf;
@@ -1103,11 +599,11 @@ php_mysqlnd_eof_read(void *_packet, MYSQLND *conn TSRMLS_DC)
PACKET_READ_HEADER_AND_BODY(packet, conn, buf, buf_len, "EOF", PROT_EOF_PACKET);
/* Should be always 0xFE */
/* Should be always EODATA_MARKER */
packet->field_count = uint1korr(p);
p++;
if (0xFF == packet->field_count) {
if (ERROR_MARKER == packet->field_count) {
php_mysqlnd_read_error_from_line(p, packet->header.size - 1,
packet->error, sizeof(packet->error),
&packet->error_no, packet->sqlstate
@@ -1160,7 +656,7 @@ size_t php_mysqlnd_cmd_write(void *_packet, MYSQLND *conn TSRMLS_DC)
{
/* Let's have some space, which we can use, if not enough, we will allocate new buffer */
php_mysql_packet_command *packet= (php_mysql_packet_command *) _packet;
MYSQLND_NET *net = &conn->net;
MYSQLND_NET *net = conn->net;
unsigned int error_reporting = EG(error_reporting);
size_t written;
@@ -1179,14 +675,14 @@ size_t php_mysqlnd_cmd_write(void *_packet, MYSQLND *conn TSRMLS_DC)
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_PACKETS_SENT_CMD);
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
php_mysqlnd_consume_uneaten_data(conn, packet->command TSRMLS_CC);
net->m.consume_uneaten_data(net, packet->command TSRMLS_CC);
#endif
if (!packet->argument || !packet->arg_len) {
char buffer[MYSQLND_HEADER_SIZE + 1];
int1store(buffer + MYSQLND_HEADER_SIZE, packet->command);
written = mysqlnd_stream_write_w_header(conn, buffer, 1 TSRMLS_CC);
written = conn->net->m.send(conn, buffer, 1 TSRMLS_CC);
} else {
size_t tmp_len = packet->arg_len + 1 + MYSQLND_HEADER_SIZE, ret;
zend_uchar *tmp, *p;
@@ -1198,7 +694,7 @@ size_t php_mysqlnd_cmd_write(void *_packet, MYSQLND *conn TSRMLS_DC)
memcpy(p, packet->argument, packet->arg_len);
ret = mysqlnd_stream_write_w_header(conn, (char *)tmp, tmp_len - MYSQLND_HEADER_SIZE TSRMLS_CC);
ret = conn->net->m.send(conn, (char *)tmp, tmp_len - MYSQLND_HEADER_SIZE TSRMLS_CC);
if (tmp != net->cmd_buffer.buffer) {
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_CMD_BUFFER_TOO_SMALL);
mnd_efree(tmp);
@@ -1229,8 +725,8 @@ void php_mysqlnd_cmd_free_mem(void *_packet, zend_bool alloca TSRMLS_DC)
static enum_func_status
php_mysqlnd_rset_header_read(void *_packet, MYSQLND *conn TSRMLS_DC)
{
size_t buf_len = conn->net.cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net.cmd_buffer.buffer;
size_t buf_len = conn->net->cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
zend_uchar *p = buf;
zend_uchar *begin = buf;
size_t len;
@@ -1241,10 +737,10 @@ php_mysqlnd_rset_header_read(void *_packet, MYSQLND *conn TSRMLS_DC)
PACKET_READ_HEADER_AND_BODY(packet, conn, buf, buf_len, "resultset header", PROT_RSET_HEADER_PACKET);
/*
Don't increment. First byte is 0xFF on error, but otherwise is starting byte
Don't increment. First byte is ERROR_MARKER on error, but otherwise is starting byte
of encoded sequence for length.
*/
if (*p == 0xFF) {
if (ERROR_MARKER == *p) {
/* Error */
p++;
php_mysqlnd_read_error_from_line(p, packet->header.size - 1,
@@ -1343,8 +839,8 @@ php_mysqlnd_rset_field_read(void *_packet, MYSQLND *conn TSRMLS_DC)
{
/* Should be enough for the metadata of a single row */
php_mysql_packet_res_field *packet= (php_mysql_packet_res_field *) _packet;
size_t buf_len = conn->net.cmd_buffer.length, total_len = 0;
zend_uchar *buf = (zend_uchar *) conn->net.cmd_buffer.buffer;
size_t buf_len = conn->net->cmd_buffer.length, total_len = 0;
zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
zend_uchar *p = buf;
zend_uchar *begin = buf;
char *root_ptr;
@@ -1359,7 +855,7 @@ php_mysqlnd_rset_field_read(void *_packet, MYSQLND *conn TSRMLS_DC)
if (packet->skip_parsing) {
DBG_RETURN(PASS);
}
if (*p == 0xFF) {
if (ERROR_MARKER == *p) {
/* Error */
p++;
php_mysqlnd_read_error_from_line(p, packet->header.size - 1,
@@ -1368,7 +864,7 @@ php_mysqlnd_rset_field_read(void *_packet, MYSQLND *conn TSRMLS_DC)
TSRMLS_CC);
DBG_ERR_FMT("Server error : (%d) %s", packet->error_info.error_no, packet->error_info.error);
DBG_RETURN(PASS);
} else if (*p == 0xFE && packet->header.size < 8) {
} else if (EODATA_MARKER == *p && packet->header.size < 8) {
/* Premature EOF. That should be COM_FIELD_LIST */
DBG_INF("Premature EOF. That should be COM_FIELD_LIST");
packet->stupid_list_fields_eof = TRUE;
@@ -1521,6 +1017,7 @@ void php_mysqlnd_rset_field_free_mem(void *_packet, zend_bool alloca TSRMLS_DC)
/* }}} */
/* {{{ php_mysqlnd_read_row_ex */
static enum_func_status
php_mysqlnd_read_row_ex(MYSQLND *conn, MYSQLND_MEMORY_POOL * result_set_memory_pool,
MYSQLND_MEMORY_POOL_CHUNK **buffer,
@@ -1576,7 +1073,7 @@ php_mysqlnd_read_row_ex(MYSQLND *conn, MYSQLND_MEMORY_POOL * result_set_memory_p
p = (*buffer)->ptr + (*data_size - header.size);
}
if ((ret = mysqlnd_read_body(conn, &header, p TSRMLS_CC))) {
if ((ret = conn->net->m.receive(conn, p, header.size TSRMLS_CC))) {
DBG_ERR("Empty row packet body");
php_error(E_WARNING, "Empty row packet body");
break;
@@ -1593,6 +1090,7 @@ php_mysqlnd_read_row_ex(MYSQLND *conn, MYSQLND_MEMORY_POOL * result_set_memory_p
*data_size -= prealloc_more_bytes;
DBG_RETURN(ret);
}
/* }}} */
/* {{{ php_mysqlnd_rowp_read_binary_protocol */
@@ -1600,44 +1098,27 @@ void php_mysqlnd_rowp_read_binary_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffe
unsigned int field_count, MYSQLND_FIELD *fields_metadata,
zend_bool persistent,
zend_bool as_unicode, zend_bool as_int_or_float,
MYSQLND_THD_ZVAL_PCACHE * zval_cache,
MYSQLND_STATS * stats TSRMLS_DC)
{
int i;
zend_uchar *p = row_buffer->ptr;
zend_uchar *null_ptr, bit;
zval **current_field, **end_field, **start_field;
#ifdef USE_ZVAL_CACHE
zend_bool allocated;
void *obj;
#endif
DBG_ENTER("php_mysqlnd_rowp_read_binary_protocol");
end_field = (current_field = start_field = fields) + field_count;
/* skip the first byte, not 0xFE -> 0x0, status */
/* skip the first byte, not EODATA_MARKER -> 0x0, status */
p++;
null_ptr= p;
p += (field_count + 9)/8; /* skip null bits */
bit = 4; /* first 2 bits are reserved */
for (i = 0; current_field < end_field; current_field++, i++) {
#ifdef USE_ZVAL_CACHE
DBG_INF("Trying to use the zval cache");
obj = mysqlnd_palloc_get_zval(zval_cache, &allocated TSRMLS_CC);
if (allocated) {
*current_field = (zval *) obj;
} else {
/* It's from the cache, so we can upcast here */
*current_field = &((mysqlnd_zval *) obj)->zv;
((mysqlnd_zval *) obj)->point_type = MYSQLND_POINTS_EXT_BUFFER;
}
#else
DBG_INF("Directly creating zval");
MAKE_STD_ZVAL(*current_field);
#endif
DBG_INF_FMT("Into zval=%p decoding column %d [%s.%s.%s] type=%d field->flags&unsigned=%d flags=%u is_bit=%d as_unicode=%d",
*current_field, i,
@@ -1703,7 +1184,6 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
unsigned int field_count, MYSQLND_FIELD *fields_metadata,
zend_bool persistent,
zend_bool as_unicode, zend_bool as_int_or_float,
MYSQLND_THD_ZVAL_PCACHE * zval_cache,
MYSQLND_STATS * stats TSRMLS_DC)
{
int i;
@@ -1718,25 +1198,12 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
end_field = (current_field = start_field = fields) + field_count;
for (i = 0; current_field < end_field; current_field++, i++) {
/* Don't reverse the order. It is significant!*/
void *obj = NULL;
zend_bool allocated = TRUE;
zend_uchar *this_field_len_pos = p;
/* php_mysqlnd_net_field_length() call should be after *this_field_len_pos = p; */
unsigned long len = php_mysqlnd_net_field_length(&p);
#ifdef USE_ZVAL_CACHE
obj = mysqlnd_palloc_get_zval(zval_cache, &allocated TSRMLS_CC);
if (allocated) {
*current_field = (zval *) obj;
} else {
/* It's from the cache, so we can upcast here */
*current_field = &((mysqlnd_zval *) obj)->zv;
((mysqlnd_zval *) obj)->point_type = MYSQLND_POINTS_FREE;
}
#else
DBG_INF("Directly creating zval");
MAKE_STD_ZVAL(*current_field);
#endif
if (current_field > start_field && last_field_was_string) {
/*
@@ -1874,9 +1341,6 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
{
ZVAL_STRINGL(*current_field, (char *) start, bit_area - start - 1, 0);
}
if (allocated == FALSE) {
((mysqlnd_zval *) obj)->point_type = MYSQLND_POINTS_INT_BUFFER;
}
} else if (Z_TYPE_PP(current_field) == IS_STRING){
memcpy(bit_area, Z_STRVAL_PP(current_field), Z_STRLEN_PP(current_field));
bit_area += Z_STRLEN_PP(current_field);
@@ -1890,9 +1354,6 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
{
ZVAL_STRINGL(*current_field, (char *) start, bit_area - start - 1, 0);
}
if (allocated == FALSE) {
((mysqlnd_zval *) obj)->point_type = MYSQLND_POINTS_INT_BUFFER;
}
}
/*
IS_UNICODE should not be specially handled. In unicode mode
@@ -1902,9 +1363,6 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
#if PHP_MAJOR_VERSION < 6
{
ZVAL_STRINGL(*current_field, (char *)p, len, 0);
if (allocated == FALSE) {
((mysqlnd_zval *) obj)->point_type = MYSQLND_POINTS_INT_BUFFER;
}
}
#else
/*
@@ -1915,10 +1373,6 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
Also the destruction of the zvals should not call zval_copy_ctor()
because then we will leak.
I suppose we can use UG(unicode) in mysqlnd.c/mysqlnd_palloc.c when
freeing a result set
to check if we need to call copy_ctor().
XXX: Keep in mind that up there there is an open `else` in
#ifdef MYSQLND_STRING_TO_INT_CONVERSION
which will make with this `if` an `else if`.
@@ -1932,20 +1386,6 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
} else {
ZVAL_UTF8_STRINGL(*current_field, (char *)p, len, 0);
}
if (allocated == FALSE) {
/*
The zval cache will check and see that the type is IS_STRING.
In this case it will call copy_ctor(). This is valid when
allocated == TRUE . In this case we can't upcast. Thus for non-PS
point_type doesn't matter much, as the valuable information is
in the type of result set. Still good to set it.
*/
if (Z_TYPE_P(*current_field) == IS_STRING) {
((mysqlnd_zval *) obj)->point_type = MYSQLND_POINTS_INT_BUFFER;
} else {
((mysqlnd_zval *) obj)->point_type = MYSQLND_POINTS_EXT_BUFFER;
}
}
#endif
p += len;
last_field_was_string = TRUE;
@@ -1969,7 +1409,7 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
static enum_func_status
php_mysqlnd_rowp_read(void *_packet, MYSQLND *conn TSRMLS_DC)
{
MYSQLND_NET *net = &conn->net;
MYSQLND_NET *net = conn->net;
zend_uchar *p;
enum_func_status ret = PASS;
size_t old_chunk_size = net->stream->chunk_size;
@@ -2000,7 +1440,7 @@ php_mysqlnd_rowp_read(void *_packet, MYSQLND *conn TSRMLS_DC)
packet->header.size = data_size;
packet->row_buffer->app = data_size;
if ((*(p = packet->row_buffer->ptr)) == 0xFF) {
if (ERROR_MARKER == (*(p = packet->row_buffer->ptr))) {
/*
Error message as part of the result set,
not good but we should not hang. See:
@@ -2013,7 +1453,7 @@ php_mysqlnd_rowp_read(void *_packet, MYSQLND *conn TSRMLS_DC)
&packet->error_info.error_no,
packet->error_info.sqlstate
TSRMLS_CC);
} else if (*p == 0xFE && data_size < 8) { /* EOF */
} else if (EODATA_MARKER == *p && data_size < 8) { /* EOF */
packet->eof = TRUE;
p++;
if (data_size > 1) {
@@ -2090,14 +1530,13 @@ void php_mysqlnd_rowp_free_mem(void *_packet, zend_bool alloca TSRMLS_DC)
/* }}} */
/* {{{ php_mysqlnd_stats_read */
static enum_func_status
php_mysqlnd_stats_read(void *_packet, MYSQLND *conn TSRMLS_DC)
{
php_mysql_packet_stats *packet= (php_mysql_packet_stats *) _packet;
size_t buf_len = conn->net.cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net.cmd_buffer.buffer;
size_t buf_len = conn->net->cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
DBG_ENTER("php_mysqlnd_stats_read");
@@ -2138,8 +1577,8 @@ static enum_func_status
php_mysqlnd_prepare_read(void *_packet, MYSQLND *conn TSRMLS_DC)
{
/* In case of an error, we should have place to put it */
size_t buf_len = conn->net.cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net.cmd_buffer.buffer;
size_t buf_len = conn->net->cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
zend_uchar *p = buf;
zend_uchar *begin = buf;
unsigned int data_size;
@@ -2153,7 +1592,7 @@ php_mysqlnd_prepare_read(void *_packet, MYSQLND *conn TSRMLS_DC)
packet->error_code = uint1korr(p);
p++;
if (0xFF == packet->error_code) {
if (ERROR_MARKER == packet->error_code) {
php_mysqlnd_read_error_from_line(p, data_size - 1,
packet->error_info.error,
sizeof(packet->error_info.error),
@@ -2219,8 +1658,8 @@ static enum_func_status
php_mysqlnd_chg_user_read(void *_packet, MYSQLND *conn TSRMLS_DC)
{
/* There could be an error message */
size_t buf_len = conn->net.cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net.cmd_buffer.buffer;
size_t buf_len = conn->net->cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) conn->net->cmd_buffer.buffer;
zend_uchar *p = buf;
zend_uchar *begin = buf;
php_mysql_packet_chg_user_resp *packet= (php_mysql_packet_chg_user_resp *) _packet;
@@ -2230,21 +1669,20 @@ php_mysqlnd_chg_user_read(void *_packet, MYSQLND *conn TSRMLS_DC)
PACKET_READ_HEADER_AND_BODY(packet, conn, buf, buf_len, "change user response", PROT_CHG_USER_PACKET);
/*
Don't increment. First byte is 0xFF on error, but otherwise is starting byte
Don't increment. First byte is ERROR_MARKER on error, but otherwise is starting byte
of encoded sequence for length.
*/
/* Should be always 0x0 or 0xFF for error */
/* Should be always 0x0 or ERROR_MARKER for error */
packet->field_count= uint1korr(p);
p++;
if (packet->header.size == 1 && buf[0] == 0xFE &&
packet->server_capabilities & CLIENT_SECURE_CONNECTION) {
if (packet->header.size == 1 && buf[0] == EODATA_MARKER && packet->server_capabilities & CLIENT_SECURE_CONNECTION) {
/* We don't handle 3.23 authentication */
DBG_RETURN(FAIL);
}
if (0xFF == packet->field_count) {
if (ERROR_MARKER == packet->field_count) {
php_mysqlnd_read_error_from_line(p, packet->header.size - 1,
packet->error_info.error,
sizeof(packet->error_info.error),
+2 -63
View File
@@ -23,6 +23,8 @@
#ifndef MYSQLND_WIREPROTOCOL_H
#define MYSQLND_WIREPROTOCOL_H
#include "mysqlnd_net.h"
#define MYSQLND_HEADER_SIZE 4
#define COMPRESSED_HEADER_SIZE 3
@@ -58,59 +60,6 @@ extern char * mysqlnd_read_body_name;
#define PACKET_READ_ALLOCA(packet, conn) PACKET_READ(&(packet), (conn))
#define PACKET_FREE_ALLOCA(packet) (packet.header.m->free_mem(&(packet), TRUE TSRMLS_CC))
/* Enums */
enum php_mysql_packet_type
{
PROT_GREET_PACKET= 0,
PROT_AUTH_PACKET,
PROT_OK_PACKET,
PROT_EOF_PACKET,
PROT_CMD_PACKET,
PROT_RSET_HEADER_PACKET,
PROT_RSET_FLD_PACKET,
PROT_ROW_PACKET,
PROT_STATS_PACKET,
PROT_PREPARE_RESP_PACKET,
PROT_CHG_USER_PACKET,
PROT_LAST, /* should always be last */
};
enum php_mysqlnd_server_command
{
COM_SLEEP = 0,
COM_QUIT,
COM_INIT_DB,
COM_QUERY,
COM_FIELD_LIST,
COM_CREATE_DB,
COM_DROP_DB,
COM_REFRESH,
COM_SHUTDOWN,
COM_STATISTICS,
COM_PROCESS_INFO,
COM_CONNECT,
COM_PROCESS_KILL,
COM_DEBUG,
COM_PING,
COM_TIME = 15,
COM_DELAYED_INSERT,
COM_CHANGE_USER,
COM_BINLOG_DUMP,
COM_TABLE_DUMP,
COM_CONNECT_OUT = 20,
COM_REGISTER_SLAVE,
COM_STMT_PREPARE = 22,
COM_STMT_EXECUTE = 23,
COM_STMT_SEND_LONG_DATA = 24,
COM_STMT_CLOSE = 25,
COM_STMT_RESET = 26,
COM_SET_OPTION = 27,
COM_STMT_FETCH = 28,
COM_DAEMON,
COM_END
};
extern const char * const mysqlnd_command_to_text[COM_END];
/* Low-level extraction functionality */
@@ -314,11 +263,6 @@ typedef struct st_php_mysql_packet_chg_user_resp {
size_t mysqlnd_stream_write_w_header(MYSQLND * const conn, char * const buf, size_t count TSRMLS_DC);
size_t mysqlnd_stream_write(MYSQLND * const conn, const zend_uchar * const buf, size_t count TSRMLS_DC);
#ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
size_t php_mysqlnd_consume_uneaten_data(MYSQLND * const conn, enum php_mysqlnd_server_command cmd TSRMLS_DC);
#endif
void php_mysqlnd_scramble(zend_uchar * const buffer, const zend_uchar * const scramble, const zend_uchar * const pass);
@@ -332,7 +276,6 @@ void php_mysqlnd_rowp_read_binary_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffe
unsigned int field_count, MYSQLND_FIELD *fields_metadata,
zend_bool persistent,
zend_bool as_unicode, zend_bool as_int_or_float,
MYSQLND_THD_ZVAL_PCACHE * zval_cache,
MYSQLND_STATS * stats TSRMLS_DC);
@@ -340,12 +283,8 @@ void php_mysqlnd_rowp_read_text_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
unsigned int field_count, MYSQLND_FIELD *fields_metadata,
zend_bool persistent,
zend_bool as_unicode, zend_bool as_int_or_float,
MYSQLND_THD_ZVAL_PCACHE * zval_cache,
MYSQLND_STATS * stats TSRMLS_DC);
enum_func_status mysqlnd_read_from_stream(MYSQLND * conn, zend_uchar * buffer, size_t count TSRMLS_DC);
#endif /* MYSQLND_WIREPROTOCOL_H */
/*
+2 -5
View File
@@ -198,7 +198,7 @@ static PHP_MSHUTDOWN_FUNCTION(mysqlnd)
/* }}} */
#if defined(PHP_DEBUG) || defined(MYSQLND_THREADED)
#if defined(PHP_DEBUG)
/* {{{ PHP_RINIT_FUNCTION
*/
static PHP_RINIT_FUNCTION(mysqlnd)
@@ -212,9 +212,6 @@ static PHP_RINIT_FUNCTION(mysqlnd)
dbg->m->set_mode(dbg, MYSQLND_G(debug));
MYSQLND_G(dbg) = dbg;
}
#endif
#ifdef MYSQLND_THREADED
MYSQLND_G(thread_id) = tsrm_thread_id();
#endif
return SUCCESS;
}
@@ -256,7 +253,7 @@ zend_module_entry mysqlnd_module_entry = {
mysqlnd_functions,
PHP_MINIT(mysqlnd),
PHP_MSHUTDOWN(mysqlnd),
#if defined(PHP_DEBUG) || defined(MYSQLND_THREADED)
#if defined(PHP_DEBUG)
PHP_RINIT(mysqlnd),
#else
NULL,
+9 -451
View File
@@ -1,454 +1,12 @@
Installing OCI8
---------------
The OCI8 Extension
------------------
0. Overview
1. Common requirements
2. Installing as a shared extension
3. Installing as a statically compiled extension
4. Installing from PECL to an existing PHP
5. Testing OCI8
6. Oracle DRCP and FAN Support
The OCI8 extension allows PHP to access Oracle databases. It can be
built using Oracle 9.2, 10, or 11 client libraries. It allows Oracle's
standard cross-version connectivity, for example PHP using Oracle 10.2
libraries can connect to Oracle Database 9.2 onwards.
This release of OCI8 can be used with PHP versions 4.3.9 to 5.x.
0. Overview
-----------
The OCI8 extension allows you to access Oracle databases. It can be
built using Oracle 9.2, 10.2, 11.1 or 11.2 client libraries, and
allows Oracle's standard cross-version connectivity. This release can
be used with PHP versions 4.3.9 to 5.x.
The OCI8 extension is not related to, or used by, PDO_OCI, the PHP
Data Objects (PDO) extension for Oracle.
1. Common requirements
----------------------
This version of PHP OCI8:
- Will build with Oracle 9.2 (or more recent) client libraries. The
same (or more recent) version of Oracle libraries used when
building OCI8 must also be used at runtime.
- Can be used with PHP versions 4.3.9 to 5.x.
If you build PHP with the "ORACLE_HOME" Oracle database or full Oracle
client libraries:
- you MUST set at least the ORACLE_HOME environment variable and
make it visible for your web server BEFORE it starts.
- the Oracle software must be readable by the web server. With
Oracle 10.2, see the $ORACLE_HOME/install/changePerm.sh script
included in patch releases.
If you build PHP with Oracle Instant Client libraries from
http://www.oracle.com/technology/tech/oci/instantclient/index.html
- either the "basic" or "basic-lite" package is required.
- the "devel" package is required.
- you don't have to set ORACLE_HOME and many of the other
environment variables to build PHP with OCI8 support.
For both ORACLE_HOME and Instant Client installs you may have to set:
- LD_LIBRARY_PATH: it must include the $ORACLE_HOME/lib or Instant
Client library directory
- NLS_LANG: if you want to change the default encoding used during
interaction with Oracle servers
The most appropriate places to add the environment variables are:
/etc/profile
/etc/profile.local
/etc/profile.d
2. Installing as a shared extension
-----------------------------------
Configure OCI8 using one of the the following configure options:
a) if you use an Oracle server or Oracle Client installation:
./configure --with-oci8=shared,$ORACLE_HOME
b) with Oracle Instant Client:
./configure --with-oci8=shared,instantclient,/path/to/instant/client/lib
If you use an RPM-based installation of Oracle Instant Client,
your configure line will look like this:
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/<version>/client/lib
Follow the usual building procedure, e.g. "make install". The OCI8
shared extension oci8.so will be created. It may need to be manually
moved to the PHP extension directory, specified by the extension_dir
option in your php.ini file.
Edit php.ini file and add the line:
extension=oci8.so
3. Installing as a statically compiled extension
------------------------------------------------
Configure OCI8 using one of the the following configure options:
a) with a common Oracle server or full Oracle client installation
./configure --with-oci8=$ORACLE_HOME
b) with Oracle Instant Client
./configure --with-oci8=instantclient,/path/to/instant/client/lib
Run "make install".
After successful compile, you do not need to add oci8.so to php.ini.
The module will be usable without any additional actions.
4. Installing from PECL to an existing PHP
------------------------------------------
The OCI8 extension is also available as a PECL module on
http://pecl.php.net/package/oci8.
Install using either (a) or (b) below.
a) Do an automated download and install:
Set PEARs proxy, if necessary:
pear config-set http_proxy http://my-proxy.example.com:80/
Run
pecl install oci8
When prompted, enter either the value of $ORACLE_HOME, or
"instantclient,/path/to/instant/client/lib" (without quotes).
b) Alternatively, manually download the PECL package, e.g. oci8-1.3.5.tgz
Extract the package:
tar -zxf oci8-1.3.5.tgz
cd oci8-1.3.5
Prepare the package:
phpize
Configure the package, either using $ORACLE_HOME or Instant Client
./configure -with-oci8=shared,$ORACLE_HOME
or
./configure -with-oci8=shared,instantclient,/path/to/instant/client/lib
Install the package:
make install
After either install, edit your php.ini file, e.g. /etc/php.ini, and
add the line:
extension=oci8.so
Make sure php.ini's "extension_dir" includes the directory that
oci8.so was installed in.
5. Testing OCI8
---------------
OCI8 tests are in ext/oci8/tests. When OCI8 tests are run this
directory will contain logs of any failures.
5.1. Running OCI8 tests on Linux
5.1.1. Edit ext/oci8/tests/details.inc
Set the username, password and connection string for the database.
Most tests have been developed using the SYSTEM account: some tests
might fail unless the user has permissions to create necessary
tables, views, procedures etc.
If the database is on the same machine as PHP, set
$oracle_on_localhost to TRUE.
If Oracle 11g Database Resident Connection Pooling is being tested,
set $test_drcp to TRUE and ensure the connection string uses an
appropriate pooled server (see section 6.2.2).
An alternative to editing details.inc is the set the environment
variables
PHP_OCI8_TEST_USER
PHP_OCI8_TEST_PASS
PHP_OCI8_TEST_DB
PHP_OCI8_TEST_DB_ON_LOCALHOST
PHP_OCI8_TEST_DRCP
for example:
$ export PHP_OCI8_TEST_USER=system
$ export PHP_OCI8_TEST_PASS=oracle
$ export PHP_OCI8_TEST_DB=localhost/XE
$ export PHP_OCI8_TEST_DB_ON_LOCALHOST=TRUE
$ export PHP_OCI8_TEST_DRCP=FALSE
5.1.2. Set any necessary environment variables for the Oracle
database. With Oracle 10g XE do:
$ . /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh
For other versions of the Oracle database do:
$ . /usr/local/bin/oraenv
5.1.3. Check your php.ini has E in the variables_order parameter, for
example:
variables_order = "EGPCS"
5.1.4. Run the tests:
$ cd <your php src directory>
$ make test TESTS=ext/oci8
5.2. The tests execute rapidly. On fast machines with a local
database configured for light load (e.g. Oracle 10g XE) you might
see random tests fail with ORA-12516 or ORA-12520 errors. To
prevent this, increase the database PROCESSES parameter using the
following steps.
5.2.1. Connect as the oracle software owner:
$ su - oracle
5.2.2. Set the necessary environment variables as in 5.1.2.
5.2.3. Start the SQL*Plus command line tool and increase PROCESSES
$ sqlplus / as sysdba
SQL> alter system set processes=100 scope=spfile
5.2.4. Restart the database:
SQL> startup force
6. Oracle DRCP and FAN Support
------------------------------
The PHP OCI8 extension has support for the Oracle Database Resident
Connection Pool (DRCP) and Fast Application Notification (FAN).
Questions and issues can be raised on the Oracle OTN forum (free
registration required):
http://www.oracle.com/technology/forums/php.html
6.1. Oracle Version Compatibility
The OCI8 extension will compile with Oracle libraries from version
9iR2 onwards. However, full functionality (e.g. DRCP support) is only
available when Oracle 11g is used.
For general database functionality the version of the Oracle libraries
used by PHP does not necessarily have to match the version of the
database.
6.2. Database Resident Connection Pooling (DRCP)
DRCP allows more efficient use of database machine memory and provides
high scalability.
For DRCP to be available in OCI8, Oracle client libraries used by PHP
and the version of the Oracle Database must both be 11g.
Documentation on DRCP is found in several Oracle manuals. For example,
see "Configuring Database Resident Connection Pooling" in the Oracle
Database Administrator's Guide 11g Release 1 (11.1)
http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/manproc004.htm#CHDGIDBA
for usage information. A whitepaper
http://www.oracle.com/technology/tech/oci/pdf/oracledrcp11g.pdf
contains background information on DRCP.
After building PHP with the OCI8 extension and 11g libraries, follow
these steps:
6.2.0 Important: if Oracle Database 11.1.0.6 with DRCP connections is
used, then the Oracle database patch for bug 6474441 must be
applied (see section 6.5). Without this patch, "ORA-01000:
maximum open cursors exceeded", "ORA-01001 invalid cursor" or
"ORA-01002 fetch out of sequence" errors may occur.
If the Oracle 11.1.0.6 database patch cannot be applied, one of
the following three workarounds can be used to disable statement
caching instead:
(i) Connect using Oracle dedicated or shared servers instead of DRCP.
(ii) Set PHP's oci8.statement_cache_size to 0.
(iii) Set an event in the database initialization parameter file:
event="56699 trace name context forever, level 128".
6.2.1. As a privileged database administrator, use a program like
SQL*Plus to start the connection pool in the database:
SQL> execute dbms_connection_pool.start_pool;
Optional settings control the size and characteristics of the
pool.
6.2.2. For PHP applications that currently connect using a Network Alias
like:
$c = oci_pconnect("myuser", "mypassword", "MYDB");
Modify your tnsnames.ora file and add the "(SERVER=POOLED)"
clause, for example:
MYDB = (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST=myhost.dom.com)
(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=sales)
(SERVER=POOLED)))
Alternatively, modify the Easy Connect syntax in PHP and add
":POOLED" after the service name:
$c = oci_pconnect("myuser", "mypassword",
"myhost.dom.com:1521/sales:POOLED");
6.2.3. Edit php.ini and choose a connection class name. This name
indicates a logical division of the connection pool and can be
used to isolate pooling for separate applications. Any PHP
instance with the same connection class value will share
connections in the pool.
oci8.connection_class = "MY_APPLICATION_NAME"
6.2.4. Run your application, connecting to the 11g database.
6.3. Fast Application Notification (FAN) Support
FAN support gives fast connection failover, a high availability
feature. This allows PHP OCI8 scripts to be notified when a database
machine or database instance becomes unavailable. Without FAN, OCI8
can hang until a TCP timeout occurs and an error is returned, which
might be several minutes. Enabling FAN in OCI8 can allow your
applications to detect errors and re-connect to an available database
instance without the web user being aware of an outage.
FAN support is available when the Oracle client libraries that PHP
links with and the Oracle Database are either version 10gR2 or 11g.
FAN benefits users of Oracle's clustering technology (RAC) because
connections to surviving database instances can be immediately made.
Users of Oracle's Data Guard with a broker will see the FAN events
generated when the standby database goes online. Standalone databases
will send FAN events when the database restarts.
For active connections, when a machine or database instance becomes
unavailable, a connection failure error will be returned by the OCI8
extension function currently being called. On a subsequent PHP script
re-connect, a connection to a surviving database instance will be
established. The OCI8 extension also transparently cleans up any idle
connections affected by a database machine or instance failure so PHP
connect calls will establish a fresh connection without the script
being aware of any service disruption.
When oci8.events is On, it is suggested to set oci8.ping_interval to
-1 to disable pinging, since enabling FAN events provide pro-active
connection management of idle connections made invalid by a service
disruption.
To enable FAN support in PHP, after building PHP with Oracle 10gR2 or
11g libraries follow these steps:
6.3.1. As a privileged database administrator, use a program like
SQL*Plus to enable the database service to post FAN events, for
example:
SQL> execute dbms_service.modify_service(
SERVICE_NAME => 'sales',
AQ_HA_NOTIFICATIONS => TRUE);
6.3.2. Edit php.ini and add
oci8.events = On
6.3.3. If your application does not already handle OCI8 error
conditions, modify it to detect failures and take appropriate
action. This may include re-connecting and re-executing
statements.
6.3.4. Run your application, connecting to a 10gR2 or 11g database.
6.4. Recommendations and Known Limitations
6.4.1 Changing Password for DRCP connections
Changing a password over DRCP connections will fail with the error
"ORA-56609: Usage not supported with DRCP". This is an documented
restriction of Oracle Database 11g.
6.4.2 Closing Connections
With the PHP OCI8 extension, persistent connections can now be closed
by the user, allowing greater control over connection resource usage.
Persistent connections will now also be closed automatically when
there is no PHP variable referencing them, such as at the end of scope
of a PHP user function. This will rollback any uncommitted
transaction. These changes to persistent connections make them behave
similarly to non-persistent connections, simplifying the interface,
allowing for greater application consistency and predictability. Use
oci8.old_oci_close_semantics=1 to retain the historical behavior.
6.4.3 LOGON Triggers can be used to set session properties
The patch for Oracle Database 11.1.0.6 bug 6474441 (see section 6.5)
allows PHP applications with DRCP connection to use a database LOGON
trigger to set session properties at the time of session creation.
Examples of such settings are the NLS language and the date format.
If the Oracle 11.1.0.6 database patch cannot be applied, one of the
following workarounds can be used:
(i) After logon, explicitly set the session properties using PHP
application code.
(ii) Connect using Oracle dedicated or shared servers instead of DRCP.
With DRCP there is an connection management relationship between (i)
DRCP's automatic pool expansion and reduction, (ii) PHP's persistent
connection caching, (iii) with the way LOGON triggers fire with DRCP
authentication. Because of this interplay, LOGON triggers in PHP
(when DRCP is used) are only recommended for setting session
attributes and not for per-PHP connection events.
6.5. Patching Oracle Database 11g
The patch for bug 6474441 is available from Oracle Support's Metalink
system.
The bug is specific to Oracle 11.1.0.6 with DRCP connections. The
issues it fixes do not affect connections using Oracle's dedicated
(the default connection mode) or shared servers. They do not affect
earlier versions of Oracle. The bug is fixed in Oracle Database
11.1.0.7.
OCI8 installation instructions and documentation is available at
http://www.php.net/oci8
+1
View File
@@ -36,6 +36,7 @@ foreach ($stmtarray as $stmt) {
$m = oci_error($s);
if (!in_array($m['code'], array( // ignore expected errors
942 // table or view does not exist
, 1918 // user does not exist
, 2289 // sequence does not exist
, 4080 // trigger does not exist
, 38802 // edition does not exist
+1 -1
View File
@@ -14,7 +14,7 @@ if ($sv == 1) {
ob_start();
phpinfo(INFO_MODULES);
$phpinfo = ob_get_clean();
$iv = preg_match('/Oracle .*Version => (11.2|12)\./', $phpinfo);
$iv = preg_match('/Oracle .*Version => (11.2|12)/', $phpinfo);
if ($iv != 1) {
die ("skip test expected to work only with Oracle 11g or greater version of client");
}
+127
View File
@@ -0,0 +1,127 @@
--TEST--
Test oci_fetch_all with 0 and -1 skip & maxrows
--SKIPIF--
<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?>
--FILE--
<?php
require(dirname(__FILE__).'/connect.inc');
// Initialization
$stmtarray = array(
"drop table fetch_all5_tab",
"create table fetch_all5_tab (mycol1 number, mycol2 varchar2(20))",
"insert into fetch_all5_tab values (1, 'abc')",
"insert into fetch_all5_tab values (2, 'def')",
"insert into fetch_all5_tab values (3, 'ghi')"
);
foreach ($stmtarray as $stmt) {
$s = oci_parse($c, $stmt);
$r = @oci_execute($s);
if (!$r) {
$m = oci_error($s);
if (!in_array($m['code'], array( // ignore expected errors
942 // table or view does not exist
, 2289 // sequence does not exist
, 4080 // trigger does not exist
, 38802 // edition does not exist
))) {
echo $stmt . PHP_EOL . $m['message'] . PHP_EOL;
}
}
}
// Run Test
echo "Test 1\n";
$s = oci_parse($c, "select * from fetch_all5_tab order by 1");
oci_execute($s);
$r = oci_fetch_all($s, $res, 0, -1);
var_dump($r);
var_dump($res);
echo "Test 1\n";
$s = oci_parse($c, "select * from fetch_all5_tab order by 1");
oci_execute($s);
$r = oci_fetch_all($s, $res, 0, 0);
var_dump($r);
var_dump($res);
echo "Test 3\n";
$s = oci_parse($c, "select * from fetch_all5_tab order by 1");
oci_execute($s);
$r = oci_fetch_all($s, $res, -1, 0);
var_dump($r);
var_dump($res);
// Clean up
$stmtarray = array(
"drop table fetch_all5_tab"
);
foreach ($stmtarray as $stmt) {
$s = oci_parse($c, $stmt);
oci_execute($s);
}
oci_close($c);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
Test 1
int(3)
array(2) {
[%u|b%"MYCOL1"]=>
array(3) {
[0]=>
%unicode|string%(1) "1"
[1]=>
%unicode|string%(1) "2"
[2]=>
%unicode|string%(1) "3"
}
[%u|b%"MYCOL2"]=>
array(3) {
[0]=>
%unicode|string%(3) "abc"
[1]=>
%unicode|string%(3) "def"
[2]=>
%unicode|string%(3) "ghi"
}
}
Test 1
int(3)
array(2) {
[%u|b%"MYCOL1"]=>
array(3) {
[0]=>
%unicode|string%(1) "1"
[1]=>
%unicode|string%(1) "2"
[2]=>
%unicode|string%(1) "3"
}
[%u|b%"MYCOL2"]=>
array(3) {
[0]=>
%unicode|string%(3) "abc"
[1]=>
%unicode|string%(3) "def"
[2]=>
%unicode|string%(3) "ghi"
}
}
Test 3
int(0)
array(0) {
}
===DONE===
+6 -14
View File
@@ -981,6 +981,10 @@ int odbc_bindcols(odbc_result *result TSRMLS_DC)
NULL, 0, NULL, &displaysize);
displaysize = displaysize <= result->longreadlen ? displaysize :
result->longreadlen;
/* Workaround for Oracle ODBC Driver bug (#50162) when fetching TIMESTAMP column */
if (result->values[i].coltype == SQL_TIMESTAMP) {
displaysize += 3;
}
result->values[i].value = (char *)emalloc(displaysize + 1);
rc = SQLBindCol(result->stmt, (SQLUSMALLINT)(i+1), SQL_C_CHAR, result->values[i].value,
displaysize + 1, &result->values[i].vallen);
@@ -1176,13 +1180,7 @@ PHP_FUNCTION(odbc_prepare)
/* Try to set CURSOR_TYPE to dynamic. Driver will replace this with other
type if not possible.
*/
int cursortype = ODBCG(default_cursortype);
if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, cursortype) == SQL_ERROR) {
odbc_sql_error(conn, result->stmt, " SQLSetStmtOption");
SQLFreeStmt(result->stmt, SQL_DROP);
efree(result);
RETURN_FALSE;
}
SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, ODBCG(default_cursortype));
}
} else {
result->fetch_abs = 0;
@@ -1572,13 +1570,7 @@ PHP_FUNCTION(odbc_exec)
/* Try to set CURSOR_TYPE to dynamic. Driver will replace this with other
type if not possible.
*/
int cursortype = ODBCG(default_cursortype);
if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, cursortype) == SQL_ERROR) {
odbc_sql_error(conn, result->stmt, " SQLSetStmtOption");
SQLFreeStmt(result->stmt, SQL_DROP);
efree(result);
RETURN_FALSE;
}
SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, ODBCG(default_cursortype));
}
} else {
result->fetch_abs = 0;
+1 -3
View File
@@ -1314,9 +1314,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl
if (!zend_is_callable(*replace, 0, &callback_name TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires argument 2, '%s', to be a valid callback", callback_name);
efree(callback_name);
*return_value = **subject;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(subject, return_value);
return;
}
efree(callback_name);
+35 -3
View File
@@ -222,6 +222,7 @@ PDO_API int php_pdo_parse_data_source(const char *data_source,
int optstart = 0;
int nlen;
int n_matches = 0;
int n_semicolumns = 0;
i = 0;
while (i < data_source_len) {
@@ -240,14 +241,21 @@ PDO_API int php_pdo_parse_data_source(const char *data_source,
/* now we're looking for VALUE; or just VALUE<NUL> */
semi = -1;
n_semicolumns = 0;
while (i < data_source_len) {
if (data_source[i] == '\0') {
semi = i++;
break;
}
if (data_source[i] == ';') {
semi = i++;
break;
if ((i + 1 >= data_source_len) || data_source[i+1] != ';') {
semi = i++;
break;
} else {
n_semicolumns++;
i += 2;
continue;
}
}
++i;
}
@@ -264,7 +272,31 @@ PDO_API int php_pdo_parse_data_source(const char *data_source,
if (parsed[j].freeme) {
efree(parsed[j].optval);
}
parsed[j].optval = estrndup(data_source + valstart, semi - valstart);
if (n_semicolumns == 0) {
parsed[j].optval = estrndup(data_source + valstart, semi - valstart - n_semicolumns);
} else {
int vlen = semi - valstart;
char *orig_val = data_source + valstart;
char *new_val = (char *) emalloc(vlen - n_semicolumns + 1);
parsed[j].optval = new_val;
while (vlen && *orig_val) {
*new_val = *orig_val;
new_val++;
if (*orig_val == ';') {
orig_val+=2;
vlen-=2;
} else {
orig_val++;
vlen--;
}
}
*new_val = '\0';
}
parsed[j].freeme = 1;
++n_matches;
break;
+2 -2
View File
@@ -44,7 +44,7 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate
char *message = NULL;
const char *msg;
if (dbh->error_mode == PDO_ERRMODE_SILENT) {
if (dbh && dbh->error_mode == PDO_ERRMODE_SILENT) {
#if 0
/* BUG: if user is running in silent mode and hits an error at the driver level
* when they use the PDO methods to call up the error information, they may
@@ -71,7 +71,7 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate
spprintf(&message, 0, "SQLSTATE[%s]: %s", *pdo_err, msg);
}
if (dbh->error_mode != PDO_ERRMODE_EXCEPTION) {
if (dbh && dbh->error_mode != PDO_ERRMODE_EXCEPTION) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", message);
} else {
zval *ex, *info;
+23 -93
View File
@@ -469,9 +469,7 @@ static PHP_METHOD(PDOStatement, execute)
param.param_type = PDO_PARAM_STR;
MAKE_STD_ZVAL(param.parameter);
*param.parameter = **tmp;
zval_copy_ctor(param.parameter);
INIT_PZVAL(param.parameter);
MAKE_COPY_ZVAL(tmp, param.parameter);
if (!really_register_bound_param(&param, stmt, 1 TSRMLS_CC)) {
if (param.parameter) {
@@ -497,6 +495,7 @@ static PHP_METHOD(PDOStatement, execute)
/* no changes were made */
stmt->active_query_string = stmt->query_string;
stmt->active_query_stringlen = stmt->query_stringlen;
ret = 1;
} else if (ret == -1) {
/* something broke */
PDO_HANDLE_STMT_ERR();
@@ -785,95 +784,24 @@ static int do_fetch_class_prepare(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
static int make_callable_ex(pdo_stmt_t *stmt, zval *callable, zend_fcall_info * fci, zend_fcall_info_cache * fcc, int num_args TSRMLS_DC) /* {{{ */
{
zval *object = NULL, **method = NULL;
char *fname = NULL, *cname;
zend_class_entry * ce = NULL, **pce;
zend_function *function_handler;
if (Z_TYPE_P(callable) == IS_ARRAY) {
if (Z_ARRVAL_P(callable)->nNumOfElements < 2) {
char *is_callable_error = NULL;
if (zend_fcall_info_init(callable, 0, fci, fcc, NULL, &is_callable_error TSRMLS_CC) == FAILURE) {
if (is_callable_error) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", is_callable_error TSRMLS_CC);
efree(is_callable_error);
} else {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied function must be a valid callback" TSRMLS_CC);
return 0;
}
object = *(zval**)Z_ARRVAL_P(callable)->pListHead->pData;
method = (zval**)Z_ARRVAL_P(callable)->pListHead->pListNext->pData;
if (Z_TYPE_P(object) == IS_STRING) { /* static call */
if (zend_lookup_class(Z_STRVAL_P(object), Z_STRLEN_P(object), &pce TSRMLS_CC) == FAILURE) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied class does not exist" TSRMLS_CC);
return 0;
} else {
ce = *pce;
}
object = NULL;
} else if (Z_TYPE_P(object) == IS_OBJECT) { /* object call */
ce = Z_OBJCE_P(object);
} else {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied function must be a valid callback; bogus object/class name" TSRMLS_CC);
return 0;
}
if (Z_TYPE_PP(method) != IS_STRING) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied function must be a valid callback; bogus method name" TSRMLS_CC);
return 0;
}
} else if (Z_TYPE_P(callable) == IS_STRING) {
method = &callable;
}
if (!method || !zend_is_callable(callable, 0, &fname TSRMLS_CC)) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied function must be a valid callback" TSRMLS_CC);
if (fname) {
efree(fname);
}
return 0;
}
if (is_callable_error) {
/* Possible E_STRICT error message */
efree(is_callable_error);
}
/* ATM we do not support array($obj, "CLASS::FUNC") or "CLASS_FUNC" */
cname = fname;
if ((fname = strstr(fname, "::")) == NULL) {
fname = cname;
cname = NULL;
} else {
*fname = '\0';
fname += 2;
}
if (cname) {
if (zend_lookup_class(cname, strlen(cname), &pce TSRMLS_CC) == FAILURE) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied class does not exist" TSRMLS_CC);
return 0;
} else {
if (ce) {
/* pce must be base of ce or ce itself */
if (ce != *pce && !instanceof_function(ce, *pce TSRMLS_CC)) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied class has bogus lineage" TSRMLS_CC);
return 0;
}
}
ce = *pce;
}
}
zend_str_tolower_copy(fname, fname, strlen(fname));
fci->function_table = ce ? &ce->function_table : EG(function_table);
if (zend_hash_find(fci->function_table, fname, strlen(fname)+1, (void **)&function_handler) == FAILURE) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "user-supplied function does not exist" TSRMLS_CC);
return 0;
}
efree(cname ? cname : fname);
fci->size = sizeof(zend_fcall_info);
fci->function_name = NULL;
fci->symbol_table = NULL;
fci->param_count = num_args; /* probably less */
fci->params = safe_emalloc(sizeof(zval**), num_args, 0);
fci->object_ptr = object;
fcc->initialized = 1;
fcc->function_handler = function_handler;
fcc->calling_scope = EG(scope);
fcc->called_scope = object ? Z_OBJCE_P(object) : NULL;
fcc->object_ptr = object;
return 1;
}
@@ -1276,9 +1204,7 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value,
zval_ptr_dtor(&return_value); /* we don't need that */
return_value = retval;
} else if (retval) {
*return_value = *retval;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(&retval, return_value);
zval_ptr_dtor(&retval);
}
}
@@ -1571,7 +1497,9 @@ static PHP_METHOD(PDOStatement, fetchAll)
case 3:
case 2:
stmt->fetch.func.function = arg2;
do_fetch_func_prepare(stmt TSRMLS_CC);
if (do_fetch_func_prepare(stmt TSRMLS_CC) == 0) {
error = 1;
}
break;
}
break;
@@ -1662,20 +1590,22 @@ static PHP_METHOD(PDOStatement, fetchAll)
static int register_bound_param(INTERNAL_FUNCTION_PARAMETERS, pdo_stmt_t *stmt, int is_param) /* {{{ */
{
struct pdo_bound_param_data param = {0};
long param_type = PDO_PARAM_STR;
param.paramno = -1;
param.param_type = PDO_PARAM_STR;
if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
"lz|llz!", &param.paramno, &param.parameter, &param.param_type, &param.max_value_len,
"lz|llz!", &param.paramno, &param.parameter, &param_type, &param.max_value_len,
&param.driver_params)) {
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|llz!", &param.name,
&param.namelen, &param.parameter, &param.param_type, &param.max_value_len,
&param.namelen, &param.parameter, &param_type, &param.max_value_len,
&param.driver_params)) {
return 0;
}
}
param.param_type = (int) param_type;
if (param.paramno > 0) {
--param.paramno; /* make it zero-based internally */
} else if (!param.name) {
+29
View File
@@ -0,0 +1,29 @@
--TEST--
PDO Common: Bug #50458 (PDO::FETCH_FUNC fails with Closures)
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded('pdo')) die('skip');
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
$db->exec("CREATE TABLE test (a VARCHAR(10))");
$db->exec("INSERT INTO test (a) VALUES ('xyz')");
$res = $db->query("SELECT a FROM test");
var_dump($res->fetchAll(PDO::FETCH_FUNC, function($a) { return strtoupper($a); }));
?>
===DONE===
--EXPECTF--
array(1) {
[0]=>
string(3) "XYZ"
}
===DONE===
+1 -1
View File
@@ -731,7 +731,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
}
if (mysqlnd_connect(H->server, host, dbh->username, dbh->password, password_len, dbname, dbname_len,
port, unix_socket, connect_opts, PDO_MYSQL_G(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL) {
port, unix_socket, connect_opts TSRMLS_CC) == NULL) {
#else
if (mysql_real_connect(H->server, host, dbh->username, dbh->password, dbname, port, unix_socket, connect_opts) == NULL) {
#endif
+2 -32
View File
@@ -57,16 +57,11 @@ PHP_INI_BEGIN()
#if PDO_DBG_ENABLED
STD_PHP_INI_ENTRY("pdo_mysql.debug", NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_pdo_mysql_globals, pdo_mysql_globals)
#endif
STD_PHP_INI_ENTRY("pdo_mysql.cache_size", "2000", PHP_INI_SYSTEM, OnUpdateLong, cache_size, zend_pdo_mysql_globals, pdo_mysql_globals)
PHP_INI_END()
/* }}} */
#endif
/* true global environment */
#ifdef PDO_USE_MYSQLND
static MYSQLND_ZVAL_PCACHE *pdo_mysqlnd_zval_cache;
#endif
/* true global environment */
/* {{{ PHP_MINIT_FUNCTION
*/
@@ -89,10 +84,6 @@ static PHP_MINIT_FUNCTION(pdo_mysql)
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_FOUND_ROWS", (long)PDO_MYSQL_ATTR_FOUND_ROWS);
REGISTER_PDO_CLASS_CONST_LONG("MYSQL_ATTR_IGNORE_SPACE", (long)PDO_MYSQL_ATTR_IGNORE_SPACE);
#ifdef PDO_USE_MYSQLND
pdo_mysqlnd_zval_cache = mysqlnd_palloc_init_cache(PDO_MYSQL_G(cache_size));
#endif
return php_pdo_register_driver(&pdo_mysql_driver);
}
/* }}} */
@@ -103,7 +94,6 @@ static PHP_MSHUTDOWN_FUNCTION(pdo_mysql)
{
php_pdo_unregister_driver(&pdo_mysql_driver);
#if PDO_USE_MYSQLND
mysqlnd_palloc_free_cache(pdo_mysqlnd_zval_cache);
UNREGISTER_INI_ENTRIES();
#endif
@@ -120,20 +110,6 @@ static PHP_MINFO_FUNCTION(pdo_mysql)
php_info_print_table_header(2, "PDO Driver for MySQL", "enabled");
php_info_print_table_row(2, "Client API version", mysql_get_client_info());
#ifdef PDO_USE_MYSQLND
{
zval values;
php_info_print_table_header(2, "Persistent cache", pdo_mysqlnd_zval_cache ? "enabled":"disabled");
if (pdo_mysqlnd_zval_cache) {
/* Now report cache status */
mysqlnd_palloc_stats(pdo_mysqlnd_zval_cache, &values);
mysqlnd_minfo_print_hash(&values);
zval_dtor(&values);
}
}
#endif
php_info_print_table_end();
#ifdef PDO_USE_MYSQLND
@@ -147,9 +123,7 @@ static PHP_MINFO_FUNCTION(pdo_mysql)
/* {{{ PHP_RINIT_FUNCTION
*/
static PHP_RINIT_FUNCTION(pdo_mysql)
{
PDO_MYSQL_G(mysqlnd_thd_zval_cache) = mysqlnd_palloc_rinit(pdo_mysqlnd_zval_cache);
{
#if PDO_DBG_ENABLED
if (PDO_MYSQL_G(debug)) {
MYSQLND_DEBUG *dbg = mysqlnd_debug_init(TSRMLS_C);
@@ -170,8 +144,6 @@ static PHP_RINIT_FUNCTION(pdo_mysql)
*/
static PHP_RSHUTDOWN_FUNCTION(pdo_mysql)
{
mysqlnd_palloc_rshutdown(PDO_MYSQL_G(mysqlnd_thd_zval_cache));
#if PDO_DBG_ENABLED
MYSQLND_DEBUG *dbg = PDO_MYSQL_G(dbg);
PDO_DBG_ENTER("RSHUTDOWN");
@@ -190,8 +162,6 @@ static PHP_RSHUTDOWN_FUNCTION(pdo_mysql)
*/
static PHP_GINIT_FUNCTION(pdo_mysql)
{
pdo_mysql_globals->mysqlnd_thd_zval_cache = NULL; /* zval cache */
pdo_mysql_globals->cache_size = 0;
#ifndef PHP_WIN32
pdo_mysql_globals->default_socket = NULL;
#endif
+6 -2
View File
@@ -63,8 +63,6 @@ static inline void PDO_DBG_ENTER(char *func_name) {}
#ifdef PDO_USE_MYSQLND
ZEND_BEGIN_MODULE_GLOBALS(pdo_mysql)
MYSQLND_THD_ZVAL_PCACHE *mysqlnd_thd_zval_cache;
long cache_size;
#ifndef PHP_WIN32
char *default_socket;
#endif
@@ -72,6 +70,12 @@ ZEND_BEGIN_MODULE_GLOBALS(pdo_mysql)
char *debug; /* The actual string */
MYSQLND_DEBUG *dbg; /* The DBG object */
#endif
#if defined(PHP_WIN32) && !PDO_DBG_ENABLED
/* dummy member so we get at least one member in the struct
* and avoids build errors.
*/
void *dummymemmber;
#endif
ZEND_END_MODULE_GLOBALS(pdo_mysql)
ZEND_EXTERN_MODULE_GLOBALS(pdo_mysql);
-2
View File
@@ -42,8 +42,6 @@ bug_45120($db);
print "done!";
?>
--XFAIL--
This is an open PDO bug. It is not a PDO_MYSQL bug
--EXPECT--
Emulated Prepared Statements
Native Prepared Statements
+61
View File
@@ -0,0 +1,61 @@
--TEST--
Bug #50323 (No ability to connect to database named 't;', no chance to escape semicolon)
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
require dirname(__FILE__) . '/config.inc';
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
function changeDSN($original, $new_options) {
$old_options = array();
$dsn = substr($original,
strpos($original, ':') + 1,
strlen($original));
// no real parser - any excotic setting can fool us
$parts = explode(';', $dsn);
foreach ($parts as $k => $v) {
$tmp = explode('=', $v);
if (count($tmp) == 2)
$old_options[$tmp[0]] = $tmp[1];
}
$options = $old_options;
foreach ($new_options as $k => $v)
$options[$k] = $v;
$dsn = 'mysql:';
foreach ($options as $k => $v)
$dsn .= sprintf('%s=%s;', $k, $v);
$dsn = substr($dsn, 0, strlen($dsn) -1);
return $dsn;
}
if (1 === @$db->exec('CREATE DATABASE `crazy;dbname`')) {
$dsn = changeDSN(getenv('PDOTEST_DSN'), array('dbname' => 'crazy;;dbname'));
$user = getenv('PDOTEST_USER');
$pass = getenv('PDOTEST_PASS');
new PDO($dsn, $user, $pass);
}
echo 'done!';
?>
--CLEAN--
<?php
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
@$db->exec('DROP DATABASE IF EXISTS `crazy;dbname`');
?>
--EXPECTF--
done!
+3 -9
View File
@@ -496,9 +496,7 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
func->funcname = estrdup(func_name);
MAKE_STD_ZVAL(func->func);
*(func->func) = *callback;
zval_copy_ctor(func->func);
INIT_PZVAL(func->func);
MAKE_COPY_ZVAL(&callback, func->func);
func->argc = argc;
@@ -575,14 +573,10 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
func->funcname = estrdup(func_name);
MAKE_STD_ZVAL(func->step);
*(func->step) = *step_callback;
zval_copy_ctor(func->step);
INIT_PZVAL(func->step);
MAKE_COPY_ZVAL(&step_callback, func->step);
MAKE_STD_ZVAL(func->fini);
*(func->fini) = *fini_callback;
zval_copy_ctor(func->fini);
INIT_PZVAL(func->fini);
MAKE_COPY_ZVAL(&fini_callback, func->fini);
func->argc = argc;
@@ -0,0 +1,130 @@
--TEST--
Testing several callbacks using PDO::FETCH_FUNC
--SKIPIF--
<?php
if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
?>
--FILE--
<?php
$db = new PDO('sqlite::memory:');
$db->exec('CREATE TABLE testing (id INTEGER , name VARCHAR)');
$db->exec('INSERT INTO testing VALUES(1, "php")');
$db->exec('INSERT INTO testing VALUES(2, "")');
$st = $db->query('SELECT * FROM testing');
$st->fetchAll(PDO::FETCH_FUNC, function($x, $y) use ($st) { var_dump($st); print "data: $x, $y\n"; });
$st = $db->query('SELECT name FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, 'strtoupper'));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, 'nothing'));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, ''));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, NULL));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, 1));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('self', 'foo')));
class foo {
public function foo($x) {
return "--- $x ---";
}
}
class bar extends foo {
public function __construct($db) {
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array($this, 'parent::foo')));
}
static public function test($x, $y) {
return $x .'---'. $y;
}
private function test2($x, $y) {
return $x;
}
public function test3($x, $y) {
return $x .'==='. $y;
}
}
new bar($db);
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test')));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test2')));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test3')));
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'inexistent')));
?>
--EXPECTF--
object(PDOStatement)#%d (1) {
[%u|b%"queryString"]=>
%string|unicode%(21) "SELECT * FROM testing"
}
data: 1, php
object(PDOStatement)#%d (1) {
[%u|b%"queryString"]=>
%string|unicode%(21) "SELECT * FROM testing"
}
data: 2,
array(2) {
[0]=>
%string|unicode%(3) "PHP"
[1]=>
%string|unicode%(0) ""
}
Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: function 'nothing' not found or invalid function name in %s on line %d
bool(false)
Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: function '' not found or invalid function name in %s on line %d
bool(false)
Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: no array or string given in %s on line %d
bool(false)
Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: no array or string given in %s on line %d
bool(false)
Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: cannot access self:: when no class scope is active in %s on line %d
bool(false)
array(2) {
[0]=>
%string|unicode%(9) "--- 1 ---"
[1]=>
%string|unicode%(9) "--- 2 ---"
}
array(2) {
[0]=>
%string|unicode%(7) "1---php"
[1]=>
%string|unicode%(4) "2---"
}
Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: cannot access private method bar::test2() in %s on line %d
bool(false)
array(2) {
[0]=>
%string|unicode%(7) "1===php"
[1]=>
%string|unicode%(4) "2==="
}
Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: class 'bar' does not have a method 'inexistent' in %s on line %d
bool(false)
+1 -1
View File
@@ -65,7 +65,7 @@ if test "$PHP_READLINE" && test "$PHP_READLINE" != "no"; then
elif test "$PHP_LIBEDIT" != "no"; then
for i in $PHP_LIBEDIT /usr/local /usr; do
test -f $i/include/readline/readline.h && LIBEDIT_DIR=$i && break
test -f $i/include/editline/readline.h && LIBEDIT_DIR=$i && break
done
if test -z "$LIBEDIT_DIR"; then
+3 -1
View File
@@ -33,8 +33,10 @@
#define rl_completion_matches completion_matches
#endif
#ifdef HAVE_LIBEDIT
#include <editline/readline.h>
#else
#include <readline/readline.h>
#ifndef HAVE_LIBEDIT
#include <readline/history.h>
#endif
@@ -1,7 +1,7 @@
--TEST--
readline_add_history(): Basic test
--SKIPIF--
<?php if (!extension_loaded("readline")) die("skip"); ?>
<?php if (!extension_loaded("readline") || !function_exists('readline_list_history')) die("skip"); ?>
--FILE--
<?php
@@ -1,7 +1,7 @@
--TEST--
readline_callback_handler_install(): Basic test
--SKIPIF--
<?php if (!extension_loaded("readline")) die("skip"); ?>
<?php if (!extension_loaded("readline") || !function_exists('readline_callback_handler_install')) die("skip"); ?>
--FILE--
<?php
@@ -1,7 +1,7 @@
--TEST--
readline_callback_handler_remove(): Basic test
--SKIPIF--
<?php if (!extension_loaded("readline")) die("skip"); ?>
<?php if (!extension_loaded("readline") || !function_exists('readline_callback_handler_remove')) die("skip"); ?>
--FILE--
<?php
@@ -1,7 +1,7 @@
--TEST--
readline_list_history(): Basic test
--SKIPIF--
<?php if (!extension_loaded("readline")) die("skip"); ?>
<?php if (!extension_loaded("readline") || !function_exists('readline_list_history')) die("skip"); ?>
--FILE--
<?php
@@ -1,7 +1,7 @@
--TEST--
readline_read_history(): Basic test
--SKIPIF--
<?php if (!extension_loaded("readline")) die("skip"); ?>
<?php if (!extension_loaded("readline") || !function_exists('readline_list_history')) die("skip"); ?>
--FILE--
<?php
@@ -1,7 +1,7 @@
--TEST--
readline_write_history(): Basic test
--SKIPIF--
<?php if (!extension_loaded("readline")) die("skip"); ?>
<?php if (!extension_loaded("readline") || !function_exists('readline_add_history')) die("skip"); ?>
--FILE--
<?php
+6 -18
View File
@@ -213,9 +213,7 @@ static void _default_get_entry(zval *object, char *name, int name_len, zval *ret
RETURN_FALSE;
}
*return_value = **value;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(value, return_value);
}
#ifdef ilia_0
@@ -3087,9 +3085,7 @@ ZEND_METHOD(reflection_class, getStaticProperties)
if (!(class_name && class_name[0] != '*' && strcmp(class_name, ce->name))) {
/* copy: enforce read only access */
ALLOC_ZVAL(prop_copy);
*prop_copy = **value;
zval_copy_ctor(prop_copy);
INIT_PZVAL(prop_copy);
MAKE_COPY_ZVAL(value, prop_copy);
add_assoc_zval(return_value, prop_name, prop_copy);
}
@@ -3212,9 +3208,7 @@ ZEND_METHOD(reflection_class, getDefaultProperties)
/* copy: enforce read only access */
ALLOC_ZVAL(prop_copy);
*prop_copy = **prop;
zval_copy_ctor(prop_copy);
INIT_PZVAL(prop_copy);
MAKE_COPY_ZVAL(prop, prop_copy);
add_assoc_zval(return_value, prop_name, prop_copy);
}
@@ -3746,9 +3740,7 @@ ZEND_METHOD(reflection_class, getConstant)
if (zend_hash_find(&ce->constants_table, name, name_len + 1, (void **) &value) == FAILURE) {
RETURN_FALSE;
}
*return_value = **value;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(value, return_value);
}
/* }}} */
@@ -4531,9 +4523,7 @@ ZEND_METHOD(reflection_property, getValue)
zend_error(E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop.name);
/* Bails out */
}
*return_value= **member;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(member, return_value);
} else {
char *class_name, *prop_name;
@@ -4542,9 +4532,7 @@ ZEND_METHOD(reflection_property, getValue)
}
zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name);
member_p = zend_read_property(ref->ce, object, prop_name, strlen(prop_name), 1 TSRMLS_CC);
*return_value= *member_p;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
MAKE_COPY_ZVAL(&member_p, return_value);
if (member_p != EG(uninitialized_zval_ptr)) {
zval_add_ref(&member_p);
zval_ptr_dtor(&member_p);
+10 -4
View File
@@ -693,11 +693,11 @@ static PHP_INI_MH(OnUpdateSaveDir) /* {{{ */
p = new_value;
}
if (PG(safe_mode) && (!php_checkuid(p, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
if (PG(safe_mode) && *p && (!php_checkuid(p, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
return FAILURE;
}
if (PG(open_basedir) && php_check_open_basedir(p TSRMLS_CC)) {
if (PG(open_basedir) && *p && php_check_open_basedir(p TSRMLS_CC)) {
return FAILURE;
}
}
@@ -1882,7 +1882,10 @@ static PHP_FUNCTION(session_unset)
}
IF_SESSION_VARS() {
HashTable *ht = Z_ARRVAL_P(PS(http_session_vars));
HashTable *ht;
SEPARATE_ZVAL_IF_NOT_REF(&PS(http_session_vars));
ht = Z_ARRVAL_P(PS(http_session_vars));
if (PG(register_globals)) {
uint str_len;
@@ -1960,7 +1963,10 @@ static PHP_FUNCTION(session_unregister)
return;
}
PS_DEL_VARL(p_name, p_name_len);
IF_SESSION_VARS() {
SEPARATE_ZVAL_IF_NOT_REF(&PS(http_session_vars));
PS_DEL_VARL(p_name, p_name_len);
}
RETURN_TRUE;
}
+4 -12
View File
@@ -1416,9 +1416,7 @@ PHP_METHOD(SoapServer, setObject)
service->type = SOAP_OBJECT;
MAKE_STD_ZVAL(service->soap_object);
*service->soap_object = *obj;
zval_copy_ctor(service->soap_object);
INIT_PZVAL(service->soap_object);
MAKE_COPY_ZVAL(&obj, service->soap_object);
SOAP_SERVER_END_CODE();
}
@@ -2335,9 +2333,7 @@ static void soap_error_handler(int error_num, const char *error_filename, const
}
fault = add_soap_fault(SOAP_GLOBAL(error_object), code, buffer, NULL, NULL TSRMLS_CC);
MAKE_STD_ZVAL(exception);
*exception = *fault;
zval_copy_ctor(exception);
INIT_PZVAL(exception);
MAKE_COPY_ZVAL(&fault, exception);
zend_throw_exception_object(exception TSRMLS_CC);
old_objects = EG(objects_store).object_buckets;
@@ -2623,9 +2619,7 @@ PHP_METHOD(SoapClient, SoapClient)
zval *class_map;
MAKE_STD_ZVAL(class_map);
*class_map = **tmp;
INIT_PZVAL(class_map);
zval_copy_ctor(class_map);
MAKE_COPY_ZVAL(tmp, class_map);
#ifdef ZEND_ENGINE_2
Z_DELREF_P(class_map);
#endif
@@ -2955,9 +2949,7 @@ static void do_soap_call(zval* this_ptr,
zval *exception;
MAKE_STD_ZVAL(exception);
*exception = *return_value;
zval_copy_ctor(exception);
INIT_PZVAL(exception);
MAKE_COPY_ZVAL(&return_value, exception);
zend_throw_exception_object(exception TSRMLS_CC);
}
#endif
+6
View File
@@ -41,6 +41,12 @@
# include "php_sockets.h"
# include "win32/sockets.h"
# define IS_INVALID_SOCKET(a) (a->bsd_socket == INVALID_SOCKET)
# ifdef EPROTONOSUPPORT
# undef EPROTONOSUPPORT
# endif
# ifdef ECONNRESET
# undef ECONNRESET
# endif
# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
# define ECONNRESET WSAECONNRESET
# ifdef errno
@@ -5,9 +5,10 @@ ext/sockets - socket_getpeername_ipv6loop - basic test
# $Id: socket_getpeername_ipv6loop.phpt 494 2009-06-09 20:38:05Z tatjana.andersen@redpill-linpro.com $
--SKIPIF--
<?php
if (!extension_loaded('sockets')) {
die('skip sockets extension not available.');
}
if (!extension_loaded('sockets')) {
die('skip sockets extension not available.');
}
require 'ipv6_skipif.inc';
?>
--FILE--
<?php
+1 -3
View File
@@ -2382,10 +2382,8 @@ SPL_METHOD(CachingIterator, __toString)
return;
}
} else if (intern->u.caching.flags & CIT_TOSTRING_USE_CURRENT) {
*return_value = *intern->current.data;
zval_copy_ctor(return_value);
MAKE_COPY_ZVAL(&intern->current.data, return_value);
convert_to_string(return_value);
INIT_PZVAL(return_value);
return;
}
if (intern->u.caching.zstr) {
Loaded 100 of 160 files, more files were not shown because too many files have changed in this diff. Show more