I figured this might be helpful to post since it seems to be a fairly common issue poking up about PHP’s limits in regard to file size. It’s no secret to fellow programmers that PHP is incapable of readily handling files over 2gb on the typical 32-bit system, but others are easily aggravated with a greeting of errors that look like this:
PHP Warning: ……. failed to open stream: File too large in ……..
Generally I’d say that if you’re trying to get PHP to man-handle huge files you’d need to have one badass server that can take that kind of abuse. Before you go about trying to compile PHP with large file support, you may want to consider passing the ‘split’ command through the system or passthru functions to break your massive files into smaller bits so PHP can handle them. If you’re the type that has to go about everything the hard way, then I guess that’s why you visited my site.
To compile PHP with large file support, you need to add a simple compiler flag preceding your configure statement. This should look as so:
# CFLAGS=”-D_FILE_OFFSET_BITS=64″ ./configure –with-modules-that-i-use
Then your make && make install and (if all goes without error) you should now be able to work with large files with PHP.
Too bad nothing’s really straight forward, eh? Apache itself has a filesize limit too (even up to 2.2.4) so don’t waste your time trying to get your newly-compiled PHP installation to work with Apache. When I was first trying to work this out I figured that it’s best to have two PHP installations, one for Apache and the other just for the CLI.
To do this, create yourself a phpinfo file and copy the configure line, removing the single quotes from around each flag. Two things you’ll want to change though:
- Remove the ”–with-apxs2=/usr/local/apache/bin/apxs‘ (or similar) flag to keep the installer from compiling against Apache
- Change your –prefix to a different location. I used ”–prefix=/usr/php-lfs’ .
When the installation is done, make it easier on yourself by creating some symlinks to the new binary:
ln -s /usr/php-lfs/bin/php /usr/bin/php5
ln -s /usr/php-lfs/bin/php /usr/local/bin/php5
This way you have your LFS-compiled PHP version in /usr/bin/php5 to use for your scripts. To call them, you’d use:
php5 /path/to/script or /usr/bin/php5 /path/to/script
What if you actually want to call the script from a browser? Well, you still can’t load a large file in the browser itself, but you can process it through a script to have a process run on the server:
<?php passthru('/usr/bin/php5 myscript.php'); ?>
And that should pretty much do it.