White Screen of Death in Silex when switching from PHP 5.3 to Php 5.4 because of "session_start"

473 views Asked by At

Finally I was able to repro the issue with the following two lines:

session_set_save_handler(new SessionHandler());
session_start();

When I do this, I get a WSOD! Any idea why this happens?

============================================================

Finally, I digged deeper and deeper and narrowed it down to the issue being caused because of failure in session_start(); Still, I do not know why it fails that way.

So, the problem boils down to: When session_start() is called in NativeSessionStorage::start(), it fails. However, when I create a sample test page which just does session_start() it succeeds!

Does Silex do anything different?!

I am keeping the text below so that anyone facing similar issue understands the reason behind the failure.

============================================================

I have tried to switch from Php 5.3 to Php 5.4 recently and my website based on Silex stopped working with a WSOD.

I checked the PHP Error Logs and I see: Premature end of script headers: php54.cgi

I tried doing a lot of stuff and finally thought of asking it online :(. Here's what I tried:

  1. Created a bare bones Silex project and checked if it is working. Nope, it wasn't.
  2. Added code before Silex is initialized and set app[debug] = true after:

    ini_set('display_errors', 1);
    error_reporting(-1);
    ErrorHandler::register();
    if ('cli' !== php_sapi_name()) {
        ExceptionHandler::register();
    }
    
  3. Tried to check the extent to which the code goes. But I was keeping on stepping in. I went till NativeSessionStorage::start() and gave up, so it was working till then and any errors I generate there were being reported properly as expected.

  4. Tried looking at other entries for how to fix BSOD, but none of them really explained how things would have changed by moving from PHP 5.3 to PHP 5.4! That is ALL I did. Just changed the PHP version and PHP.INI accordingly. Below is the PHP.INI I use now.

    ;                           |PIG v0.3.2.1|
    [PHP]
      open_basedir = 
      engine = 1
      zend.ze1_compatibility_mode = 
      short_open_tag = 1
      asp_tags = 
      precision = 14
      y2k_compliance = 1
      output_buffering = 4096
      zlib.output_compression = 
      implicit_flush = 
      unserialize_callback_func = 
      serialize_precision = 100
      allow_call_time_pass_reference = 
      safe_mode = 
      ; safe_mode_gid = 1
      safe_mode_include_dir = 
      safe_mode_exec_dir = 
      safe_mode_allowed_env_vars = "PHP_"
      safe_mode_protected_env_vars = "LD_LIBRARY_PATH"
      disable_functions = exec,passthru,shell_exec,system,proc_open,popen,show_source 
      disable_classes = 
      highlight.string = "#DD0000"
      highlight.comment = "#FF9900"
      highlight.keyword = "#007700"
      highlight.bg = "#FFFFFF"
      highlight.default = "#0000BB"
      highlight.html = "#000000"
      expose_php = 1
      max_execution_time = 30
      max_input_time = 60
      memory_limit = 128M
      error_reporting = 6135
      display_errors = 1
      display_startup_errors = 
      log_errors = 1
      log_errors_max_len = 1024
      ignore_repeated_errors = 
      ignore_repeated_source = 
      report_memleaks = 1
      track_errors = 
      html_errors = 
      error_log = "/hsphere/local/var/httpd/logs/php54_error.log"
      variables_order = EGPCS
      register_globals = 0
      ; register_long_arrays = 1
      register_argc_argv = 1
      auto_globals_jit = 1
      post_max_size = 30M
      ; magic_quotes_gpc = 1
      magic_quotes_runtime = 
      magic_quotes_sybase = 
      auto_prepend_file = 
      auto_append_file = 
      default_mimetype = "text/html"
      always_populate_raw_post_data = 1
    
    
    ;***** Added by go-pear
    include_path=".:/hsphere/shared/php54/include/php/PEAR"
    ;*****
    
      doc_root = 
      user_dir = 
      extension_dir = "/hsphere/shared/php54/lib/php/extensions/no-debug-non-zts-20100525/"
      cgi.fix_pathinfo = 1
      file_uploads = 1
      upload_tmp_dir = 
      upload_max_filesize = 25M
      allow_url_fopen = 1
      allow_url_include = 
      default_socket_timeout = 60
      auto_detect_line_endings = 1
    [Syslog]
      define_syslog_variables = 
    [mail function]
      sendmail_path = /usr/sbin/sendmail -t -i [email protected]
      mail.force_extra_parameters = 
    [SQL]
      sql.safe_mode = 
    [ODBC]
      odbc.allow_persistent = 
      odbc.check_persistent = 1
      odbc.max_persistent = "-1"
      odbc.max_links = "-1"
      odbc.defaultlrl = 4096
      odbc.defaultbinmode = 1
    [MySQL]
      mysql.allow_persistent = 
      mysql.max_persistent = "-1"
      mysql.max_links = "-1"
      mysql.default_port = 3306
      mysql.default_socket = "/var/lib/mysql/mysql.sock"
      mysql.default_host = localhost
      mysql.default_user = 
      mysql.default_password = 
      mysql.connect_timeout = 60
      mysql.trace_mode = 
    [MySQLi]
      mysqli.max_links = "-1"
      mysqli.default_port = 3306
      mysqli.default_socket = "/var/lib/mysql/mysql.sock"
      mysqli.default_host = localhost
      mysqli.default_user = 
      mysqli.default_pw = 
      mysqli.reconnect = 
    [PostgresSQL]
      pgsql.allow_persistent = 
      pgsql.auto_reset_persistent = 
      pgsql.max_persistent = "-1"
      pgsql.max_links = "-1"
      pgsql.ignore_notice = 0
      pgsql.log_notice = 0
    [dbx]
      dbx.colnames_case = lowercase
    [bcmath]
      bcmath.scale = 0
    [Session]
      session.save_handler = files
      session.save_path = "${US_ROOTF}/tmp"
      session.use_cookies = 1
      session.use_only_cookies = 1
      session.name = PHPSESSID
      session.auto_start = 0
      session.cookie_lifetime = 0
      session.cookie_path = /
      session.cookie_domain =
      session.cookie_httponly =
      session.serialize_handler = php
      session.gc_probability = 1
      session.gc_divisor = 1000
      session.gc_maxlifetime = 1440
      session.bug_compat_42 = Off
      session.bug_compat_warn = Off
      session.referer_check =
      session.cache_limiter = nocache
      session.cache_expire = 180
      session.use_trans_sid = 0
      session.hash_function = 0
      session.hash_bits_per_character = 5
      url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
    [Assertion]
      assert.active = 1
      assert.warning = 1
      assert.bail = 
      assert.callback = 0
      assert.quiet_eval = 0
    [Sockets]
      sockets.use_system_read = 1
    [mbstring]
      mbstring.language = Neutral
      mbstring.internal_encoding = "EUC-JP"
      mbstring.http_input = pass
      mbstring.http_output = pass
      mbstring.encoding_translation = 
      mbstring.detect_order = auto
      mbstring.substitute_character = 
      mbstring.func_overload = 0
    [exif]
      exif.encode_unicode = "ISO-8859-15"
      exif.decode_unicode_motorola = "UCS-2BE"
      exif.decode_unicode_intel = "UCS-2LE"
      exif.encode_jis = 
      exif.decode_jis_motorola = JIS
      exif.decode_jis_intel = JIS
    [soap]
      soap.wsdl_cache_enabled = 1
      soap.wsdl_cache_dir = "/tmp"
      soap.wsdl_cache_ttl = 86400
    [Zend]
    zend_extension="/hsphere/shared/php54/lib/php/extensions/ZendGuardLoader.so"
    ;  zend_extension_manager.optimizer = "/usr/local/Zend/lib/Optimizer-3.3.3"
    ;  zend_extension_manager.optimizer_ts = "/usr/local/Zend/lib/Optimizer_TS-3.3.3"
    ;  zend_optimizer.version = "3.3.3"
    ;  zend_extension = "/usr/local/Zend/lib/ZendExtensionManager.so"
    ;  zend_extension_ts = "/usr/local/Zend/lib/ZendExtensionManager_TS.so"
    [suhosin]
    ;  extension = suhosin.so
      suhosin.executor.include.max_traversal = 4
      suhosin.executor.disable_emodifier = 0
      suhosin.executor.include.whitelist = "http://,https://,file://,bfa://"
      suhosin.executor.allow_symlink = 0
      suhosin.mail.protect = 1
      suhosin.upload.disallow_elf = 1
      suhosin.log.syslog = 511
      suhosin.log.syslog.facility = 8
      suhosin.log.syslog.priority = 1
      suhosin.log.sapi = 511
      suhosin.session.encrypt = 0
      suhosin.cookie.cryptua = 0
      suhosin.session.cryptdocroot = 0
      suhosin.cookie.cryptdocroot = 0
      suhosin.executor.include.whitelist="phar"
      suhosin.get.max_value_length = 10240
    [curl]
    extension=curl.so
    [gmp]
    extension=gmp.so
    [iconv]
    extension=iconv.so
    [imap]
    extension=imap.so
    [mysqli]
    extension=mysqli.so
    [mysql]
    extension=mysql.so
    [odbc]
    extension=odbc.so
    [pdo]
    extension=pdo.so
    [pdo_mysql]
    extension=pdo_mysql.so
    [pdo_pgsql]
    extension=pdo_pgsql.so
    [pdo_sqlite]
    extension=pdo_sqlite.so
    [pgsql]
    extension=pgsql.so
    [sqlite3]
    extension=sqlite3.so
    [htscanner]
    extension=htscanner.so
    [mongo]
    extension=mongo.so
    [date]
    date.timezone=EST
    

I used the tools provided by the control panel of my hosting account to make the switch, so I am pretty sure it must be proper. I am able to run other PHP scripts.

2

There are 2 answers

0
datashovel On

Perhaps run 'strace' to see where PHP is failing. Perhaps you have permissions issues based on what user is trying to access certain resources. For example the directory where sessions are supposed to be saved.

0
maddob On

I think I had the same problem before. If you are using PHP Version < 5.4.11 - there is a bug in the SessionHandler implementation - check this link out, maybe it is somehow related...