faqts : Computers : Programming : Languages : PHP : Common Problems : Errors

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

13 of 15 people (87%) answered Yes
Recently 3 of 4 people (75%) answered Yes

Entry

What is the "Unable to initialize a new token cache" error?

Jun 9th, 1999 07:00
Nathan Wallace, Zeev Suraski


It could be one of a few things.

First, you might be running out of memory (either your system really
goes out of memory, or you might have a limit imposed on your shell in
some way).

Another possibility to look at, especially if your application
repeatedly calls include() or eval() many times, is the following.

PHP 3.0 imposes an arbitrary limit on the number of token caches it can
create (usually 12 bit, or 4096 token caches).  Each include() or eval()
statement generates a new token cache.  Simple math will suggest you can
call include() and eval() upto 4095 times (combined), as the first token
cache is taken by the main file.  On the 4096th include()/eval() - you'd
get that error.

Possible solutions for this problem are:
1.  Waiting for PHP 4.0, which imposes no arbitrary limits of any kind.
2.  Changing the constants in token_cache.h to accomodate for more token
caches.  Edit token_cache.h, find where it defined TOKEN_BITS, and lower
the number to something lower than the default (which is 20).  Every bit
you decrease here, doubles the amount of token caches you can generate
(e.g., if you reduce it to 18, you can generate upto 16384 token caches
instead of 4096).
You may wonder why not to simply reduce that number to a zero and get a
whopping 4,294,967,296 number of token caches.  The explanation is
simple.  The lower TOKEN_BITS is, the smaller each token cache can be,
which limits the size of code you may have in each file in your PHP
application.  You'd simply have to conduct a few trials to see how well
stuff works for you (reducing it to 19 or 18 should be safe, programs
that require token caches that big are very rare).

After your change that constant in token_cache.h, be sure to recompile
PHP and possibly relink it with Apache (if you use an Apache module).

Again, very soon you won't have to worry about it any longer.