PHP意外终止脚本

I'm working in PHP and creating a system with a lot of PHP-driven elements and I have noticed that some of my pages stop displaying text produced using the echo command.

I have made a small example of this. Of course, my program is not supposed to just print allt numbers from 1 to 10000, but this example demonstrates how the script just terminates without any warnings.

Example code:

<?php
    for ($i = 1; $i <= 10000; $i++) {
        echo $i, '<br>';
    }
?>

Output:

1
2
More numbers...
8975
8976
8977
8

What is causing this? Is it a buffer issue, and how do I resolve it?

The fact that your code ran to completion on the cli suggests to me that your script is exceeding the ini.max_execution_time runtime configuration.

Note in the linked documentation that the value of this configuration on the cli is 0 which means it does not time out when run in that environment.

The default setting in the browser is 30 seconds.

You can show your current setting in the browser with:

echo ini_get('max_execution_time');

And you should be able to increase it with:

ini_set('max_execution_time', 0); // turns off timeout

If the script you have shown us behaves as you describe the there's something very wrong going on. If this is a Unix or Linux based system and its repeatedly exhibiting this behaviour then the kernel is terminating the script - unless it has been configured not to do so, the kernel will be forcing a core dump of the process.

Either go build a new system to run your code on or Google how to capture and diagnose a core dump on your operating system.

update

If xdebug is reporting the process is still running then it probably hasn't dumped its core, but "not producing output" != "not running". What state is the process in? What happens when you redirect the ouput? What is the end-to-end output channel when it misbehaves?

The problem did not lie directly with my PHP installation or the application itself, but somewhere in my IDE PHPStorm. When running the code with the same PHP interpreter outside of the IDE's wrappers, it all works fine. The procedures described by the many users here helped with that. Thank you.