0

I have managed categories in admin section. Each category fetches json feed from url and some of them we updates in admin backend and save in database. Each category feeds have approx. 100 records , some feeds may have more than 500 records. I want to collect id of all of these feeds in one array. and want to compare ids array from database. because feeds are changing gradually so that i have some raw record in database

So in my array there is more than 10,000 ids. What is limit of array we can store in php array ?

Vipin Singh
  • 543
  • 2
  • 8
  • 24
  • since arrays using memory of your host pc it will depend is it 32bit or 64bit. And how much memory you have. so at simple, pretty much long – Strahinja Djurić Jan 12 '16 at 08:57

2 Answers2

1

There is no limit of an array (maximum) you can store as you can but there is a limit on your script.

You can change the script memory limit by using memory_limit in your php.ini file.

When you get the error "Out of memory" than you need to modified your script memory as i mentioned above memory_limit .

One last thing, sometime you didn't have access to modify your php.ini than you can also use like this in your php file.

ini_set('memory_limit','128M'); // or something larger

Side Note:

If you change memory_limit from php.ini file, than you must need to restart APACHE.

devpro
  • 16,184
  • 3
  • 27
  • 38
1

Yes, there's a limit on the maximum number of elements. The hash table structure (arrays are basically wrappers around a hash table) is defined like this:

typedef struct _hashtable {
    uint nTableSize;
    uint nTableMask;
    uint nNumOfElements;
    ulong nNextFreeElement;
    Bucket *pInternalPointer;   /* Used for element traversal */
    Bucket *pListHead;
    Bucket *pListTail;
    Bucket **arBuckets;
    dtor_func_t pDestructor;
    zend_bool persistent;
    unsigned char nApplyCount;
    zend_bool bApplyProtection;
#if ZEND_DEBUG
    int inconsistent;
#endif
} HashTable;

given that

typedef unsigned int uint;

the limit is the maximum size of an unsigned int (typically 2^32-1 on a 32-bit OS and on most 64-bit OS).

In practice, however, except on machines with lots of RAM and 32-bit ints, you will always hit the memory limit before this becomes an issue.

source: PHP: do arrays have a maximum size?

Community
  • 1
  • 1
Chetan Ameta
  • 7,696
  • 3
  • 29
  • 44