Using module SHMOP to speed up PHP5!

xiaoxiao2021-03-06  81

MMCache's latest version has been seriously incompatible with PHP5. I looked at the source code of PHP5 and accidentally found a SHM module - SHMOP.

Pondle its instruction document, I wrote an immature function:

/*AUTHOR: Tmgh@www.deyang.gov.cn

I personally use this function to display the home page (anyway, the CMS content management system, no time update, set the $ TIME to 1200 seconds), check the column, check the specific one, I use JPCache to cache

* /

Function GetContent ($ TIME) {$ SHM_ID = Shmop_Open (0xFF4, "C", 0644, 20); if ($ SHM_ID) {$ SHM_SIZE = Shmop_Size ($ SHM_ID); $ MyDate = Shmop_read ($ SHM_ID, 0, $ SHM_SIZE ); shmop_close ($ date ("ymdhis"); if ($ date- $ mydate> = $ time) {$ DATE = DATE ("ymdhis"); $ shm_id = shmop_open (0xff4, "c ", 0644, 20); $ shm_bytes_written = shmop_write ($ SHM_ID, $ DATE, 0); shmop_close ($ SHM_ID); ob_start (); maincontent (); $ data = ob_get_contents (); $ shm_id = shmop_open (0xff3," C ", 0644, Strlen ($ data)); $ shm_bytes_written = shmop_write ($ SHM_ID, $ DATA, 0); shmop_close ($ shm_id);} else {$ shm_id = shmop_open (0xff3," A ", 0644, 150000) ; $ shm_size = shmop_size ($ shm_id); $ my_string = shmop_read ($ shm_id, 0, $ shm_size); shmop_close ($ shm_id); echo $ my_string;}} else {$ date = date ( "YmdHis"); $ shm_id = shmop_open (0xFF4, "C", 0644, 20); $ shm_bytes_written = shmop_write ($ SHM_ID, $ DATE, 0); Shmop_close ($ SHM_ID); OB_Start (); maincontent (); $ data = ob_get_contents (); $ SHM_ID = shmop_open (0xFF3, "C", 0644, Strlen ($ data)); $ shm_bytes_written = shmop_write ($ SHM_ID, $ DATA, 0); SHMOP_CLOSE ($ SHM_ID);}}

Where maincontent () is a function, it is necessary to accelerate the content of the page, such as:

Function maincontent () {/ * can be anything in this function. The code that needs to be accelerated is directly written directly. * / $ smarty = new smarty; $ smarty-> display ('title.tpl'); $ smarty-> display ('index.tpl'); $ smarty-> display ('footer.tpl');}

The test results are compared:

Before using this acceleration code, the result of using AB-N2000-C64 -DS http: // localhost / derived: Transfer Rate: 33.25 [KBYTES / SEC]

Use this acceleration code:

Transfer Rate: 6382.55 [KBYTES / SEC]

The current speed is the previous 6382.55 / 33.25 = 191.96 times!

Function Description: $ TIME in GetContent ($ TIME) is a cache time; SHMOP is a memory access module, 0xff3 and 0xff4 are KEY I will take. I am using the platform: Win2000 apache2.1-dev php5 mysql. Specific description in PHP: http://www.php.net/manual/en/ref.shmop.php

No MMCache accelerates PHP5! I am very satisfied. The code is not optimized, and interested people can modify themselves. After all, OpenSource. Haha.

转载请注明原文地址:https://www.9cbs.com/read-121895.html

New Post(0)