PHP 生成一个完全白色的页面,没有错误、日志或标题。

发布于 2024-08-15 05:16:13 字数 771 浏览 5 评论 0原文

在我的私人 WAMP PC 上运行一些 PHP 代码时,我突然从服务器收到空白响应 - 实际上没有响应。 PHP 错误日志中没有标头、没有数据、什么都没有,什么也没有。我重新启动了 APACHE 和 PHP,但仍然没有任何结果。我知道 php 正在运行,因为我可以很好地访问其他 PHP 脚本。

Firebug 报告没有标头,?字节,并且只需要163ms来“加载”(所以这不是超时)。我考虑过快速内存消耗 - 但我监控了我的电脑内存,没有显示任何峰值。到目前为止,错误和异常一直运行良好。

到底是什么?

max_execution_time = 30 ;
max_input_time = 60 ; 
max_input_nesting_level = 64 ; 
memory_limit = 500M ;

error_reporting = E_ALL | E_NOTICE | E_STRICT
display_errors = On
log_errors = On

:编辑:

我不会用十英尺长的杆子碰@。我认为 Ruby 开发人员把它放在那里,这样程序员就会放弃 PHP。

不管怎样,我启用了xdebug,它没有输出任何grind文件。然后我采纳了 zombat 的建议,在页面顶部放置了一个 DIE() ,它起作用了。我想我只是有一些非常奇怪的代码,它们完全杀死了 PHP。即使使用 @ 禁用或抑制错误,我仍然应该从服务器返回一个包含空内容的标头!

如果我找到更多,我会回复。

While running some PHP code on my private WAMP PC I'm suddenly getting a blank response from the server - no response actually. No headers, no data, nothing in the PHP error logs, nada. I restarted APACHE and PHP but still nothing. I know php is working because I can access other PHP scripts just fine.

Firebug reports no headers, ? bytes, and it only takes 163ms to "load" (so it's not a timeout). I thought about rapid memory consumption - but I monitored my PC's memory and it's not showing any spikes. Errors and Exceptions have been working fine until now.

What in the world?

max_execution_time = 30 ;
max_input_time = 60 ; 
max_input_nesting_level = 64 ; 
memory_limit = 500M ;

error_reporting = E_ALL | E_NOTICE | E_STRICT
display_errors = On
log_errors = On

:EDIT:

I wouldn't touch @ with a ten-foot-pole. I think the ruby guys throw that in there so programmers would drop PHP.

Anyway, I enabled xdebug and it didn't output any grind files. Then I took zombat's advice and placed a DIE() at the top of the page and it worked. I guess that I just have some very weird code that totally kills PHP. Even if errors were disabled or suppressed with @ I should still be getting back a header from the server with the empty content!

If I find more I'll post back.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

深居我梦 2024-08-22 05:16:13

从控制台运行该页面,您将收到错误消息。

// nix
php yourFile.php

// Windows
c:\path\to\php.exe yourFile.php

Run the page from a console and you'll get the error message.

// nix
php yourFile.php

// Windows
c:\path\to\php.exe yourFile.php
秋凉 2024-08-22 05:16:13

此目录中可能有一个 .htaccess 文件,该文件已修改错误报告。

要进行测试,请尝试在 php 脚本顶部显式设置这些选项,这会给您带来麻烦。

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

我也看到过这种情况是由过度热心的防病毒软件包引起的。有些包含网络代理软件来过滤互联网和电子邮件。在这种情况下,页面只会继续加载到无限大,但永远不会完成。

You could have a .htaccess file in this directory which has modified error reporting.

To test, try explicitly setting these options at the top of your php script which is giving you trouble.

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

I've also seen this caused by over-zealous anti-virus packages. Some contain web proxy software to filter internet and email. In that case, the page would just continue load into infinity but never complete.

So要识趣 2024-08-22 05:16:13

您说其他 PHP 脚本正在运行,这表明这可能不是 Apache 问题。您的所有日志记录设置似乎也都是正确的,并且没有记录任何内容,因此 PHP 很可能在输出任何内容之前正常退出。以下情况之一可能是正确的:

  • exit() 语句放错了位置?您正在编写代码,也许您添加了一个快速 exit() 来检查某些内容,但忘记将其删除?
  • don.neufeld 的检查 @ 运算符的使用(抑制任何错误消息)的想法在过去花费了我数小时的调试时间。绝对是值得寻找的东西。

在这种情况下,穷人的调试方法可以快速产生结果。在此处添加 exit('wtf'); 作为相关脚本的第一行。那运行吗?那个测试的结果,无论结果如何,都立即排除了各种可能性。如果没有得到任何输出,则可能是服务器级别的问题(配置、错误模块等),但要小心任何更高级别的缓冲。如果您确实得到了输出,那么您就知道服务器没有问题,并且问题出在您的脚本中更深层,在这种情况下,您可以将 exit() 调用向下移动几行,冲洗并重复。这不是一种优雅的调试方式,但它快速且肮脏,您可能会在几分钟内找到问题。

You say other PHP scripts are working, so that indicates it's probably not an Apache problem. You also appear to have all your logging settings correct, and nothing is getting logged, so it's quite possible PHP is exiting normally before it outputs anything. One of the following could be true:

  • A misplaced exit() statement? You were working on the code, maybe you added a quick exit() to check something out, and forgot to remove it?
  • don.neufeld's idea of checking for the use of the @ operator, which suppresses any error messages, has cost me hours of debugging time in the past. Definitely something to look for.

In situations like this, the poor man's debugging approach can yield some quick results. Throw an exit('wtf'); in as the first line in the script in question here. Does that run? The results of that test immediately rules out all sorts of possibilities no matter what the result is. If you don't get any output, then it's probably a server-level problem (configuration, bad module, etc), although be careful of any higher-level buffering. If you do get output, then you know the server is fine, and the issue lies deeper in your script, in which case you can move the exit() call down a few lines, rinse and repeat. Not an elegant way to debug, but it's quick and dirty, and you'll probably find the issue in a couple of minutes.

清欢 2024-08-22 05:16:13

请注意@(错误抑制)运算符,如果@ 行中出现语法错误,PHP 将默默退出。

要检测这种情况,请使用 set_error_handler 并编写自己的错误处理程序,您仍然会因使用 @ 的错误而被调用。

Beware the @ (error suppression) operator, if you have a syntax error on a line with @ PHP will silently exit.

To detect this condition, use set_error_handler and write your own error handler, you'll still get called for errors where @ is used.

爱要勇敢去追 2024-08-22 05:16:13

检查 php.ini 设置中的short_open_tag = On或short_open_tag = Off

Check php.ini setting for short_open_tag = On or short_open_tag = Off

耳根太软 2024-08-22 05:16:13

这里最有可能的是apache崩溃了。也许查看 apache 错误日志,或者附加一个调试器。

有关在 Windows 上调试 apache/php 进程的详细信息,请访问 http:// /bugs.php.net/bugs-generate-backtrace-win32.php

The most likely thing here is that apache is crashing. Look through the apache error log maybe, or attach a debugger.

Details on looking debugging the apache/php process on windows can be found at http://bugs.php.net/bugs-generating-backtrace-win32.php

再浓的妆也掩不了殇 2024-08-22 05:16:13

我猜到了这个问题的答案 - 事实证明 PHP 5.2.5 无法处理递归死亡。

<?php

class A
{
    public function __construct()
    {
        new B;
    }
}

class B 
{
    public function __construct()
    {
        new A;
    }
}

new A;

print 'Loaded Class A';

没有标题、错误、内容、日志、xdebug 转储、内存峰值、CPU 峰值、服务器崩溃或任何其他内容。大约 150 毫秒后,PHP 就“结束”了。诡异的。

I guessed the answer to this problem - it turns out that PHP 5.2.5 can't handle a recursive death.

<?php

class A
{
    public function __construct()
    {
        new B;
    }
}

class B 
{
    public function __construct()
    {
        new A;
    }
}

new A;

print 'Loaded Class A';

No headers, errors, content, logs, xdebug dumps, memory spikes, CPU spikes, server crashes, or anything. After about 150ms PHP just "ends". Weird.

自在安然 2024-08-22 05:16:13

要在 PHP 代码中激活错误显示,以防万一您看不到任何内容,请插入

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

示例,这可能会节省您大量时间:

joomla default.php 模板文件中的此代码显示一个空白页面,没有错误消息,没有第 20 行和 21

17  <?php if ($params->get('title_article_linkable')) { ?>
18      <a href="<?php 
19          $url = JRoute::_(ContentHelperRoute::getArticleRoute($item->id,$item->catid));
20          ini_set('display_errors',1);
21          error_reporting(E_ALL);
22          echo $url; ?>">
23      <?php echo $this->item->title; ?></a> // should be $item->title !!
24  <?phpLL000000 } else { ?>
25      <?php echo $item->title; ?>
26  <?php } ?>

输出:

在此处输入图像描述

To activate error display in your PHP code in case you don't see anything, insert

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

Example where this potentialy saves you a lot of time:

This code in a joomla default.php template file displays a blank page with no error msg without lines 20 and 21

17  <?php if ($params->get('title_article_linkable')) { ?>
18      <a href="<?php 
19          $url = JRoute::_(ContentHelperRoute::getArticleRoute($item->id,$item->catid));
20          ini_set('display_errors',1);
21          error_reporting(E_ALL);
22          echo $url; ?>">
23      <?php echo $this->item->title; ?></a> // should be $item->title !!
24  <?phpLL000000 } else { ?>
25      <?php echo $item->title; ?>
26  <?php } ?>

Output:

enter image description here

醉梦枕江山 2024-08-22 05:16:13

检查事件日志。

check the Event Log.

夏日浅笑〃 2024-08-22 05:16:13

发生这种情况时,通常值得删除尽可能多的代码,看看是否可以在页面上显示一些内容。

这可能是由于代码中某处未闭合的引用或未闭合的大括号造成的。这可能会导致 echo 语句被视为文本或在另一个函数中,等等。

并且,虽然应该报告所有错误,但我发现并非所有错误都被实际报告,可能是因为共享主机上的 ini 设置是我够不到的。

注释掉并不总是足够的——不知道为什么不这样做。发生这种情况时,我通常发现最快的方法是复制页面,然后慢慢地将部分剪切并粘贴回去,直到找到错误,然后我就可以因为愚蠢的打字错误而踢自己一脚。

When this happens, it is usually worth cutting out as much as possible of the code and seeing if you can get something on the page to show.

It could be due to an unclosed quote somewhere in your code, or an unclosed brace. This might cause the echo statement to be viewed as text or in another function, etc.

And, while all errors SHOULD be being reported, I have found that not all errors are actually reported, probably because of ini settings on a shared host that is out of my reach.

Commenting out is not always enough - not sure why not. When this happens, I usually find it to be quickest just to copy the page, and slowly cut and paste sections back in till I find the error, after which I can kick myself for a silly typo.

晒暮凉 2024-08-22 05:16:13

我遇到了同样的问题,因为我使用的是:

ob_flush()

I had the same problem because I was using:

ob_flush()

吻风 2024-08-22 05:16:13

您是否检查过文件的结束 ?> 标记?或者更重要的是它们后面的任何空格......

did you check your files for closing ?> tags? Or more importantly any whitespace after them...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文