doushan9415 2015-06-08 10:36
浏览 211

PHP - strtotime和date导致长时间执行和超时

I have a MySQL query which selects and then loops through all records (about 200 rows). There are 2 date cells for each row, which are displayed like this:

date('d/m/Y', strtotime($row['date_created']));
date('d/m/Y', strtotime($row['date_edited']));

The issue is that these two causes script to run for a long time and eventually time out. When checking the server log, I found these errors:

(70007)The timeout specified has expired: ap_content_length_filter: apr_bucket_read() failed
ap_pass_brigade failed with error 70007: The timeout specified has expired

Both fields in db table are specified as datetime. Displaying them without date format modifications works well. What causes this issue and how to resolve it? Never experienced these issues with dates before.

Here is a simplified query:

$result = mysql_query("SELECT date_created, date_edited FROM news");
while($row = mysql_fetch_array($result)) {
    //date lines above here
}

Without strtotime and date it prints out right away, no delay.

  • 写回答

1条回答 默认 最新

  • dongyan1808 2015-06-08 12:48
    关注

    That's weird.

    You can try formatting date in SQL query itself using DATE_FORMAT().

    eg.

    $result = mysql_query( "SELECT DATE_FORMAT( date_created, '%d/%m/%Y' ) as date_created, DATE_FORMAT( date_edited, '%d/%m/%Y' ) as date_edited FROM news" );
    while( $row = mysql_fetch_array( $result ) ) {
        //print as-it-is
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP