If you are using a webserver on which you have installed an opcode cache, like APC, eval
will not be the "best solution" : eval'd code is not store in the opcode cache, if I remember correctly (and another answer said the same thing, btw).
A solution you could use, at least if the code is not often changed, is get a mix of code stored in database and included code :
- when necessary, fetch the code from DB, and store it in a file on disk
- include that file
- as the code is now in a file, on disk, opcode cache will be able to cache it -- which is better for performances
- and you will not need to make a request to the DB each time you have to execute the code.
I've worked with software that uses this solution (the on-disk file being no more than a cache of the code stored in DB), and I worked not too bad -- way better that doing loads of DB requests of each page, anyway...
Some not so good things, as a consequence :
- you have to fetch the code from the DB to put it in the file "when necessary"
- this could mean re-generating the temporary file once every hour, or deleting it when the entry in DB is modified ? Do you have a way to identify when this happens ?
- you also have to change your code, to use the temporary file, or re-generate it if necessary
- if you have several places to modifiy, this could mean some work
BTW : would I dare saying something like "eval is evil" ?