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

PHP FTP脚本大文件处理无HTTP错误却失败,求Apache配置参数

Handling Large File Transfers in Your PHP/AJAX Script: Apache & PHP Config Tweaks

First off, the fact that you’re not getting a 500 error means your script isn’t crashing from a fatal PHP error—instead, it’s likely hitting a timeout, resource limit, or connection constraint that’s silently killing the process mid-operation. Let’s break down the key Apache (and related PHP) settings you need to adjust to support 220MB+ files (and larger ones down the line):

Apache Configuration Adjustments

These settings belong in your Apache config file (httpd.conf, apache2.conf, or a virtual host-specific .conf file):

  • LimitRequestBody
    This controls the maximum size of an HTTP request body. While the default is often 0 (unlimited), some hosting environments enforce a low cap. To avoid blocking your AJAX POST trigger (even if the payload is small) and accommodate future larger operations, set it to a value bigger than your target file size or disable the limit entirely:

    LimitRequestBody 0
    # Or set a specific size (e.g., 512MB = 536870912 bytes)
    # LimitRequestBody 536870912
    

    Place this inside the <Directory> block pointing to your PHP script’s folder, or your <VirtualHost> section.

  • Timeout
    Large FTP transfers (download/upload) take time—Apache’s default timeout is usually 300 seconds (5 minutes), which might not be enough for 220MB files depending on your connection speed. Bump this up to a more generous value:

    Timeout 1800
    

    This sets the timeout to 30 minutes; adjust based on your expected transfer speeds.

PHP Configuration Tweaks (Critical for Script Execution)

Even if Apache is configured correctly, PHP has its own limits that will halt your script before it finishes handling large files. Edit your php.ini file (or use ini_set() in your script if your hosting allows it):

  • max_execution_time
    Sets the maximum time (in seconds) a PHP script can run. The default 30 seconds is way too short for large FTP operations. Increase it:

    max_execution_time = 1800
    
  • max_input_time
    Controls how long PHP waits to receive input (like your AJAX POST data). For long-running scripts, set this to match your execution time:

    max_input_time = 1800
    
  • memory_limit
    Your script needs enough memory to handle file data during transfers. For a 220MB file, set this to at least 256MB (or higher for larger files):

    memory_limit = 256M
    
  • post_max_size
    While your script uses FTP, if your AJAX POST includes any payload (even small metadata), ensure this is larger than that payload size:

    post_max_size = 512M
    

Bonus: FTP Connection Timeouts

Don’t forget to adjust the timeout for your FTP connections directly in the PHP script. PHP’s default FTP timeout might cut off long transfers before they finish. Use ftp_set_option() right after connecting to a server:

$ftp_conn = ftp_connect('server-a.example.com');
// Set FTP timeout to 5 minutes (300 seconds)
ftp_set_option($ftp_conn, FTP_TIMEOUT_SEC, 300);

After making these changes, restart Apache and PHP-FPM (if you’re using it) to apply the settings. Test with your 220MB file first, then scale up to confirm everything works as expected.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:27:30