PHP + Large files

I was working on the project Hotelotravel for last few months and as usual in many cases it involved working with large database files because when you consider all hotels, locations and images all over the world it means a lot. But if we want to do large file uploads or database updates with PHP there are few configurations to be done to default settings and I’m putting this as a note to myself (I’m always keep forgetting this) as well as to any one who may find this useful like when importing a large backup file through phpMyAdmin.

In your php.ini check for these settings and change them as you need.

  • post_max_size (The maximum size of post data you can send in one submission)
  • upload_max_filesize (Maximum size of file that can be uploaded)
  • memory_limit (Maximum memory limit that can be allocated for a script execution)
  • max_execution_time (Maximum time limit for a script execution)

As a side note, if you trying to import large files (backups.etc) through phpMyAdmin and it refuses, you may need to edit file and change these settings to 0 which means no limit.

  • $cfg[‘ExecTimeLimit’]
  • $cfg[‘MemoryLimit’]

As a final note, these settings are there for a purpose. So my advice is change them in whatever manner  you want in a development environment but be very careful when setting them in a production environment because an endless execution of a script can cause your servers to waste bandwidth and even crash.  So I guess this is my disclaimer 😉

Tagged ,

8 thoughts on “PHP + Large files

  1. Erik Snoeijs says:

    While phpmyadmin is a handy tool, when working with large datasets i often find it much easier/faster to import them locally, by ssh’ing to the server, scp’ing the sql file over and doing a “mysql –user=user -password database_name < mysql_file”

  2. Laknath says:

    @Erik Yep, that’s another way. But if the backup is compressed to gz or Bz2 and compared to the time ssh’ing, I don’t see much difference.

  3. […] Semage submitted a new blog post he’s written up about working with large file uploads in your PHP […]

  4. […] Semage submitted a new blog post he’s written up about working with large file uploads in your PHP […]

  5. point47 says:

    Recently I had a clienti with a wordpress blog that wanted to upload some large videos.
    The problem was that I have a virtual private served with many more clients and I didn’t want to give a universal post_max_size. So a good alternative that I found was using .htaccess.
    So I put a .htaccess file in the admin folder and gave post_max_size acces only to those scripts:

    php_value post_max_size “40M”
    php_value upload_max_filesize “40M”

    or you can use: to set that right just for one file.

    Hope this helps some one!

  6. point47 says:

    it seems the tags were escaped:D
    i put spaces after the < sign (hope it works now :D)

    php_value post_max_size “40M”
    php_value upload_max_filesize “40M”

    and for one file

  7. point47 says:

    I put [ instead of < … you need to change that

    [FilesMatch “.(php)$”]
    php_value post_max_size “40M”
    php_value upload_max_filesize “40M”

  8. Laknath says:

    @point47 Good point. Thanks 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *