What's the maximum number of keys for an array in php

后端 未结 10 1603
一整个雨季
一整个雨季 2021-02-08 03:32

I\'m writing a php script where I call

$lines = file(\'base_list.txt\');

to break a file up into an array. The file has over 100,000 lines in

相关标签:
10条回答
  • 2021-02-08 03:56

    Edit: As Rob said, if your application is running out of memory, chances are it won't even get to the print_r line. That's kinda my hunch as well, but if it is a memory issue, the following might help.

    Take a look in the php.ini file for this line, and perhaps increase it to 16 or more.

    memory_limit = 8M
    

    If you don't have access to php.ini (for example if this was happening on a shared server) you can fix it with a .htaccess file like this

    php_value memory_limit 16M
    

    Apparently some hosts don't allow you to do this though.

    0 讨论(0)
  • 2021-02-08 04:00

    Is it possible there is an inherent limit on the output from print_r. I'd suggest looking for the first and last line in the file to see if they are in the array. If you were hitting a memory limit inserting into the array you would never have gotten to the print_r line.

    0 讨论(0)
  • 2021-02-08 04:02

    every time ive run out of memory in PHP i've received an error message stating that fact. So, I'd also say that if you're running out of memory then the script wouldn't get to the print_r()

    try enabling auto_detect_line_endings in php.ini or by using
    ini_set('auto_detect_line_endings', 1). There may be some line endings that windows doesn't understand & this ini option could help. more info about this ini option can be found here

    0 讨论(0)
  • 2021-02-08 04:04

    Two suggestions:

    1. Count the actual number of items in the array and see whether or not the array is the correct number of entries (therefore eliminating or identifying print_r() as the culprit)

    2. Verify the input... any chance that the line endings in the file are causing a problem? For example, is there a mix of different types of line endings? See the manual page for file() and the note about the auto_detect_line_endings setting as well, though it's unlikely this is related to mac line endings.

    0 讨论(0)
  • 2021-02-08 04:05

    I believe it is based on the amount of available memory as set in the php.ini file.

    0 讨论(0)
  • 2021-02-08 04:11

    If you're outputting to something like Internet Explorer, you might want to make sure it can display all the information you're trying to put there. I know there's a limit to an html page, but I'm not sure what it is.

    0 讨论(0)
提交回复
热议问题