Saturday, February 22, 2014

PHP Parse error: syntax error, unexpected $end for large PHP file ~ 4000 lines


When you have exhausted checking closing brackets and missing semi-colons using this awesome tool PHP Lint (http://www.icosaedro.it/phplint/phplint-on-line.html) and you are still getting the dreaded 
PHP Parse error:  syntax error, unexpected $end.
 
Then I have a solution that may help.  On rare occasion, you may need to up the memory allowed for PHP. Usually it's when I deal with large files and don't necessarily care about optimizing the file reading process but simply getting the file opened. There's an easy way to increase to amount of memory allowed to PHP right in your script:
ini_set('memory_limit','16M');
The above code will increase the maximum amount of memory available to PHP to 16 MB. Again, the setting is only adjusted for the running script. 
PHP Fatal error:  Allowed memory size of 16777216 bytes exhausted (tried to allocate 6144 bytes) 
Well that wasn't even enough but at least I got a logical error this time. I  increased to 32M and it worked.