Ramblings of a wanderer

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 config.inc.php 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 😉

8 thoughts on “PHP + Large files”

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”

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: