Zero size response: PHP crashes when assigning to a variable

I sometimes have a problem that allows the web browser to display the message “Zero response size” (Firefox). Chrome displays "ERR_EMPTY_RESPONSE". I am using CodeIgniter (still version 2.xx).

In the call, I check some post variables, insert a database record and send an email. However, the email method downloads the language file for the log message. At the end of this call in the /core/Lang.php class system, the file is included and the array of classes is expanded.

The next line (Lang.php, line 126) executes the following statement:

$this->is_loaded[] = $langfile; 

The array is initialized, and this is usually normal. But in this special case, this is the exact line that causes the PHP server to crash (my explanation for the empty answer I get).

Now I am running PHP 5.5.19, but the error also appears from 5.2.17.

Any explanation why this is happening? If I try to reproduce the error by assigning the variable in the same way, I never get the same message. Also, the only similarity in cases where I get this error is that I sent mail earlier.

Update : here PHP_INFO: http://awesumgrades.ch/phpinfo.php

Update 2 : here is what I tried for sure:

I tried to reset everything to this line:

 var_dump($this->is_loaded); var_dump($langfile); exit("I reached here"); $this->is_loaded[] = $langfile; 

Getting this result:

 array(0) { } string(14) "email_lang.php" I reached here 

Now when I do this (put the array job in front):

 $this->is_loaded[] = $langfile; var_dump($this->is_loaded); var_dump($langfile); exit("I reached here"); 

I get ERR_EMPTY_RESPONSE (chrome).

When I dump $this , this is an object:

 object(CI_Lang)#11 (2) { ["language"]=> array(0) { } ["is_loaded"]=> array(0) { } } 

When I return to the calling function, I got the following lines (in core / libraries / Email.php):

 protected function _set_error_message($msg, $val = '') { $CI =& get_instance() $CI->lang->load('email'); // <-- this is the call which gets to the other method 

I put the following lines in front of the email downloader:

 $CI =& get_instance(); var_dump($this); var_dump($CI); exit(); $CI->lang->load('email'); 

This displays the entire object that I cannot publish here for the security reasons of my site. If you need a specific property or part of an object, I will provide it here.

Currently, I am still waiting for the Apache log from my hoster, if it is here, I will publish it.

Update 3 . I just tried to just comment out the line again, but then the script crashes in the next line, which clarifies that the accident is absolutely not related to the logic of the Lang.php class, but this seems to be a mistake of a larger class (I tried to print the memory, but I do not have permission for memory_get_usage() ....

FINAL UPDATE

I finally got to my hoster, which provided me with apache error logs, but there were no hints of the specified error.

However, now the magic is complete: after smcjones' answer I added a line

 ini_set('display_errors', 1); 

in the very first line in CI index.php and set error_reporting to E_ALL again. However, as soon as I run the code with this set of lines, the error will not be repeated - even if I set display_errors to 0 . When I comment the line again, the error will be repeated. Also, when I delete error_reporting(E_ALL) , an error occurs despite ini_set .....

I had no idea what was changing with these lines, but it looks like with a call to ini_set () and error_reporting, maybe some routine might turn on, which was missing otherwise - I don't know.

It once again indicates how the magic of PHP can sometimes be - it never ceases to amaze me.

+6
source share
3 answers

It looks like your log level is not high enough to receive non-fatal errors. PHP can simply gracefully shut down if there is an error that is not set to display.

I understand that you should receive errors based on your CI configuration, but you cannot receive warnings. Any warnings you receive can be the key.

Please try to put this at the top of your file (before any output and headers):

 ini_set('display_errors', 1); error_reporting(E_ALL); 

When updating your browser, you should not receive a blank page.

Another thing you can try, as a slightly better long-term patch, is this:

 ini_set('display_errors', 0); error_reporting(E_ERROR); 

If this works, then stick with it, because there is less chance of showing custom things that you don't want to see.

Ultimately, based on a change in behavior (incorrectly) when using the PHP configuration functions, this is due to the fact that it is related to Apache or to the PHP configuration, which is specific to the node. Since you cannot handle your host, I recommend switching hosts (there are many good host options available) or at least telling your host that you cannot stay with them unless they fix everything that’s wrong.

+2
source

Lang.php uses the file to load error messages that belong to your library and the helper that we download.

Why?

 Path - `system/language/english` 

In the above path (go to email_lang.php ) you will see that there is an error message. Therefore, when we use the library, we use echo $this->email->print_debugger(); to print error messages that we can see in the browser. In fact, all these error messages come from here.

How??

 Path - `system/language/english` 

In the above path, you can check for multiple files that end with the suffix _lang.php . Therefore, in the Lang.php file (you can verify that in Lang.php is line 65-132), they remove the entire suffix _lang and .php . Therefore, finally, it only downloads the file with a secondary name. If email_lang.php it will return only email . So finally, it will upload the file to $this->is_loaded[] = $langfile; and it will set print_debugger

Any reason

As simple CI tricks we use $this->email for our purpose. In fact, the email here contains two diferet files / methods.

  • E-Mail Helper (which we load via the address $this->load->library('email'); )
  • lang file support (which we load through the Lang.php address)

so they both come together to give us one service.

Will it affect my CI project?

No. Bcz it will load, we use only the library.

You may ask a question. Does it freeze when using the library? .
Oh, never . When you open the file, you can see that there are only error messages. No functions, no arithmetic operations, etc. The value of the array is also simple with some error.


Do not use

  var_dump($this->is_loaded); var_dump($langfile); 
  • when you do this several times the browser freezes. Bcz you are loading an object.
  • Like not using dump() , this will not be good.
0
source

There are not many tips to solve your problem: S In any case, I think you are probably getting a PHP error, and since this line is so small, I think the cause of the problem is that you are trying to add an element to a nonexistent array . I have to try:

 if (is_array($this->is_loaded)) { $this->is_loaded[] = $langfile; } 

To find additional information about the problem:

  • Could you enable the development environment at the top level of index.php?

     define('ENVIRONMENT', 'development'); 
  • Could you enable the CodeIgniter profiler?

     $this->output->enable_profiler(TRUE); 
  • Could you take a look at the apache error log?

-1
source

All Articles