时间:2021-07-01 10:21:17 帮助过:14人阅读
- <br>[hidef] <br>int ANSWER = 42; <br>str HX = "9enjoy"; <br>float PIE = 3.14159; <br><br>这里整数用int,浮点数用float,字符串用str。<br>字符串str的值使用双引号来包含,或者直接写字符串内容。如果使用单引号,将会把单引号也做为字符串的内容。<br>如str HX='9enjoy',实际存储的不是9enjoy,是'9enjoy'。<br><br>4、重新加载php-fpm即可<br><br># /usr/local/webserver/php/sbin/php-fpm reload<br><br>此时,查看phpinfo()的结果,在hidef处就可以看到定义的变量。<br><br><br>-----------------------------------------------------------------------------<br><br>附:<br><br>如果使用了APC,apc提供了定义常量的方法。apc_define_constants和apc_load_constants。apc_define_constants将常量转为数组存到一个user cache中。虽然把常量存在了内存中,但每次PHP请求时,仍然需要读cache,分别定义,因此也不会有什么明显的性能提升。我测试了下定义25个常量,使用apc的函数比直接定义常量快了0.01ms。<br><br>这样使用:<br>if(!apc_load_constants('defined')) {<br> $constants = array(<br> 'HX' => TRUE,<br> 'D_BUG' => 1<br> );<br> apc_define_constants('defined', $constants);<br>}<br><br>define() is notoriously slow. Since the main benefit of APC is to increase the performance of scripts/applications, this mechanism is provided to streamline the process of mass constant definition. However, this function does not perform as well as anticipated. <br><br>For a better-performing solution, try the hidef extension from PECL.