aebstract Posted March 6, 2010 Share Posted March 6, 2010 Okay, this script: <?php $textData = file('array.txt'); echo "hello"; ?> hello is echo'd to the browser, no problems. If I change array.txt to array2.txt, it gives a white page and doesn't seem to even try to do anything. array.txt is just under 1MB array2.txt is just over 71MBs Is there a limit on file size that can be opened? Cause I don't think it's hitting something inside and stopping, it seems to not even be attempting to look inside the file. Any other information needed for this problem? Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2010 Share Posted March 6, 2010 Of course there are limits, such as the amount of available memory. You should be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying all the errors it detects. Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022353 Share on other sites More sharing options...
Anti-Moronic Posted March 6, 2010 Share Posted March 6, 2010 My first piece of advice would be to turn on error reporting and/or check your php error logs. That usually reveals 99.9% of errors and should give you a better idea of why this isn't working. 71mb isn't all that big so can't see why it wouldn't work when you open that as oppose to your smaller file. There could be a parse error but it's doubtful. I don't think anything within the file could cause a parse error. Get those errors and I'm sure we'd be able to help more. Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022354 Share on other sites More sharing options...
aebstract Posted March 6, 2010 Author Share Posted March 6, 2010 Sorry for not running that, which was completely stupid: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 75023834 bytes) in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 8 Is this something I can change or do I have to have my host change it? Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022355 Share on other sites More sharing options...
Anti-Moronic Posted March 6, 2010 Share Posted March 6, 2010 Yeh, you've ran out of memory. You need to change the php ini directive: memory_limit Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022360 Share on other sites More sharing options...
aebstract Posted March 6, 2010 Author Share Posted March 6, 2010 Trying to locate the php.ini, waiting on a response from web host. Is there a way to force the memory_limit through a manual run script before trying to read the file? Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022373 Share on other sites More sharing options...
aebstract Posted March 6, 2010 Author Share Posted March 6, 2010 I created an .htaccess file with this: php_value memory_limit 100M and in my phpinfo() it says the memory_limit is 100M for local and 32M for master. I'm now getting a white page and no error. I can't echo anything before the read(). Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022377 Share on other sites More sharing options...
salathe Posted March 6, 2010 Share Posted March 6, 2010 A far more useful solution would be to go through the file (often line-by-line) so as to only load a small portion of it into memory at any one time. Unless there is some particular need to load 71 MB into memory every time the script is executed, I would advise against it. I'd also echo the others' suggestion of enabling and displaying all errors during development. Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022379 Share on other sites More sharing options...
aebstract Posted March 6, 2010 Author Share Posted March 6, 2010 A far more useful solution would be to go through the file (often line-by-line) so as to only load a small portion of it into memory at any one time. Unless there is some particular need to load 71 MB into memory every time the script is executed, I would advise against it. I'd also echo the others' suggestion of enabling and displaying all errors during development. I placed this at the top: error_reporting(E_ALL); ini_set("display_errors", 1); but, with the .htaccess fix I mentioned above, I'm not getting an error just white space. I could do it one line at a time, but not too sure where to start as to write that, as right now I have a little function to do some array work so I can loop through every value and insert it in to the database. This is going to be a one time access deal, then it will be trashed and never ran again. Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022380 Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2010 Share Posted March 6, 2010 If you read the documentation for the memory_limit setting, you will find out where you can change it. For example, if your web host has not prevented it, you can set memory_limit in a script using an ini_set() statement. Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022385 Share on other sites More sharing options...
meltingpoint Posted March 6, 2010 Share Posted March 6, 2010 salathe- How would one EFFECTIVELY do this? go through line by line.................. Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022393 Share on other sites More sharing options...
aebstract Posted March 6, 2010 Author Share Posted March 6, 2010 Okay, I have my memory_limit set to 100M now, I am getting now errors but am still getting a blank white page. I have an echo statement ABOVE my file() and it isn't getting displayed either. Could something in the file be causing it to do this? If so, what would trigger such an event? Wouldn't I still get information up until the point that it causes error? The smaller file still works, the larger one is just blanking out. Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022413 Share on other sites More sharing options...
aebstract Posted March 6, 2010 Author Share Posted March 6, 2010 I got an email from my host and he said this is the error that was being displayed: [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 48 [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 49 [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 50 [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 51 [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 52 [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 53 [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 54 [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 55 [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 56 [sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice: Undefined offset: 0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 57 Quote Link to comment https://forums.phpfreaks.com/topic/194344-max-file-size-with-file/#findComment-1022418 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.