You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter 4中set_time_limit()无效,CURL大文件上传超时求助

CodeIgniter 4 大文件CURL上传超时问题解决办法

1. 配置CURLRequest的超时参数

set_time_limit()仅控制PHP脚本的执行超时,但CURL请求本身有独立的超时配置,必须在请求时明确设置:

public function uploadDataJabs()
{ 
    $client = \Config\Services::curlrequest();
    set_time_limit(3600);

    // 发起带超时配置的上传请求(按需调整目标地址和上传字段)
    $response = $client->request('POST', '你的目标上传接口地址', [
        'multipart' => [
            [
                'name'     => 'upload_file', // 对应接口接收的字段名
                'filename' => 'large_file.zip', // 本地文件名
                'contents' => fopen('/path/to/your/large_file.zip', 'r') // 以流模式读取文件
            ]
        ],
        'timeout' => 3600, // CURL请求总超时时间(秒)
        'connect_timeout' => 60 // 连接服务器的超时时间(秒)
    ]);
}

2. 调整服务器层面的超时限制

服务器自身的超时规则会覆盖PHP配置,需对应修改:

  • Apache:在httpd.conf或站点目录的.htaccess中添加/修改:
    Timeout 3600
    KeepAliveTimeout 60
    
  • Nginx:在站点配置文件中添加/修改:
    client_max_body_size 100M; # 根据实际文件大小调整,如200M
    proxy_read_timeout 3600s;
    fastcgi_read_timeout 3600s;
    

3. 检查PHP.ini核心配置

确保PHP全局配置支持大文件上传和长时执行:

  • max_execution_time = 3600
  • upload_max_filesize = 100M
  • post_max_size = 120M(需大于upload_max_filesize)
  • memory_limit = 256M(根据文件大小适当调高)

修改后重启Web服务器(Apache/Nginx)和PHP服务生效。

内容的提问来源于stack exchange,提问作者Nyoman Gunartha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 18:32:09