php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #59839 Adding report_errors parameter to session handler
Submitted: 2011-07-05 17:48 UTC Modified: -
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:3 (100.0%)
From: mkoppanen@php.net Assigned:
Status: Open Package: memcache (PECL)
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-07-05 17:48 UTC] mkoppanen@php.net
Description:
------------
This adds additional diagnostics for memcache(d) errors:

Output with the patch when memcached is down:

# php -d"session.save_path='tcp://localhost:11211?report_errors=1'" -r 'session_start ();'

Warning: session_start(): Server localhost (tcp 11211, udp 0) failed with: Connection refused (111) in Command line code on line 1

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at Command line code:1) in Command line code on line 1

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at Command line code:1) in Command line code on line 1

Warning: Unknown: Failed to write session data (memcache). Please verify that the current setting of session.save_path is correct (tcp://localhost:11211?report_errors=1) in Unknown on line 0

Without the patch:

# php -d"session.save_path='tcp://localhost:11211'" -r 'session_start ();'

Warning: Unknown: Failed to write session data (memcache). Please verify that the current setting of session.save_path is correct (tcp://localhost:11211?report_errors=0) in Unknown on line 0

Reproduce code:
---------------
Index: memcache_session.c
===================================================================
--- memcache_session.c  (revision 312942)
+++ memcache_session.c  (working copy)
@@ -39,6 +39,12 @@
        PS_MOD(memcache)
 };
 
+static void php_mmc_session_failure_callback(mmc_pool_t *pool, mmc_t *mmc, void *param TSRMLS_DC) /* {{{ */
+{
+       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Server %s (tcp %d, udp %d) failed with: %s (%d)",
+               mmc->host, mmc->tcp.port, mmc->udp.port, mmc->error, mmc->errnum);
+}
+
 /* {{{ PS_OPEN_FUNC
  */
 PS_OPEN_FUNC(memcache)
@@ -122,6 +128,13 @@
                                        retry_interval = Z_LVAL_PP(param);
                                }
 
+                               if (zend_hash_find(Z_ARRVAL_P(params), "report_errors", sizeof("report_errors"), (void **) &param) != FAILURE) {
+                                       convert_to_boolean_ex(param);
+                                       if (Z_BVAL_PP(param)) {
+                                               pool->failure_callback = &php_mmc_session_failure_callback;
+                                       }
+                               }
+
                                zval_ptr_dtor(&params);
                        }
 


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Nov 11 23:01:33 2019 UTC