Alex Rivera | Logout

Can defining a lot of constants cause performance or memory problems?

Asked 2011-08-15T06:11:41.820
15

I have a website which uses a lot of constants, that are defined like this, for example:

define('CONSTANT', 1)

I currently have a list of about 200 defines like this. This list is run every time a page loads. Is this going to affect my performance or memory use badly?

Edit
Report

2 Answers

5

I would imagine not. Are you having performance issues with your script? If not, then don't worry about it. If so, then what have you done to determine where the bottleneck lies?

If you need to know how long it's taking to include and parse the file with your defines in, then I'd suggest you time it.

$start = microtime (true);
include ('file_to_include.php');
echo (microtime (true) - $start);
answered 2011-08-15T06:16:25.123
0

I don't think it will have more impact than reading the file that contains 200 constants, then again it will be optimized by your disk cache. At least it is better than reading 200 constants from database. If you do care about performance, install an op cache, therefore, it will not require any additional parsing every time. For memory it depends on the type of your constants but it wont be much.

answered 2011-08-15T06:21:51.657

Your Answer