PHP 5.5到5.6 strtotime()挂起

时间:2017-12-01 07:49:46

标签: php

我一直在测试从PHP 5.5到5.6的迁移并清除错误。我发现了一个,我不知道如何解决,我的ISP坚定我的代码的问题。

将问题缩小到strtotime()问题需要4天时间。看一下以下内容。我多年来一直在使用类似的脚本,但现在当我在PHP 5.6下测试它时,它失败了。当我将循环从10更改为25时,服务器只会挂起并停止响应。

<?
/*
test for PHP 5.6 and strtotime() not working correctly
for ($e2 = 0; $e2 < 25; $e2++) { // if this is set active, the script does not load and eventually times out under PHP 5.6
for ($e2 = 0; $e2 < 10; $e2++) { // if this is set active, the script completes properly under PHP 5.6
*/
    for ($e2 = 0; $e2 < 25; $e2++) {
        $today=date('Y-m-d',strtotime());
        $lastmodyear=date('Y-m-d',strtotime("+ $e2 months"));
        $lastmodY=date('Y',strtotime("+ $e2 years"));
        $contents .= "<div>Empty: $today / Month: $lastmodyear / Year: $lastmodY</div>";
    }
    echo "$contents";

?>

1 个答案:

答案 0 :(得分:0)

传递给可能偶然发现此问题的其他人。这是我的解决方案。

将此添加到脚本顶部:

date_default_timezone_set("America/New_York");

现在它将在PHP 5.6下正确完成:

<?
date_default_timezone_set("America/New_York");
/*
test for PHP 5.6 and strtotime() not working correctly
for ($e2 = 0; $e2 < 25; $e2++) { // if this is set active, the script does not load and eventually times out under PHP 5.6
for ($e2 = 0; $e2 < 10; $e2++) { // if this is set active, the script completes properly under PHP 5.6
strtotime() expects at least 1 parameter // understood, but should not end with the session timing out with a 504 error and only when <25??
*/
    for ($e2 = 0; $e2 < 25; $e2++) {
        $today=date('Y-m-d',strtotime());
        $lastmodyear=date('Y-m-d',strtotime("+ $e2 months"));
        $lastmodY=date('Y',strtotime("+ $e2 years"));
        $contents .= "<div>Empty: $today / Month: $lastmodyear / Year: $lastmodY</div>";
    }
    echo "$contents";

?>
相关问题