0060 | PHP Dynamic page static HTML generator

Monday, May 25th, 2009 Posted in PHP Coding, Programming, Web Server | 4 Comments »

ชื่อยาวเป็นวา code อะไรวะ (วันหลังมา search จะเจอมั้ยเนี่ยตู 555)

code นี้แปะด้านบนสุดของไฟล์ (จะใส่ใน auto prepend เลยก็ยังไหว)

<?php
$_cachetime = 43200;
$_info = parse_url($_SERVER["REQUEST_URI"]);
if (!isset($_info['query'])) $_info['query'] = '';
$_path = end(explode('/', $_info['path']));
$_info['query'] = str_replace('&nocache', '', $_info['query']);
$_info['query'] = str_replace('nocache&', '', $_info['query']);
$_info['query'] = str_replace('nocache', '', $_info['query']);
$_cachename = sprintf("%x", crc32($_path."?".$_info['query']));
$_cachefolder = '/path/to/cache/'.substr($_cachename,0,2).'/';
$_cachefile = $_cachefolder.$_cachename;
if ($_SERVER["REQUEST_URI"] != '/' && $_SERVER["REQUEST_METHOD"] == 'GET' &&
    !isset($_GET["nocache"]) &&
    file_exists($_cachefile) && filemtime($_cachefile) > time() - $_cachetime) {
        readfile($_cachefile);
        exit();
}
function fetch_cache($_buffer) {
        global $_cachefile, $_cachefolder;
        umask( 0);
        if (!file_exists($_cachefolder))
                mkdir($_cachefolder,0777, true);
        if ($_h = fopen($_cachefile, "w")) {
                fwrite($_h, $_buffer);
                fclose($_h);
        }
        return $_buffer;
}
ob_start('fetch_cache');
?>

code นี้ใส่ด้านท้าย (ใน auto append ก็ได้นะครับ)

<?php
ob_end_flush();
?>

* แก้ไขเพิ่ม 2009/05/28

Tags: , ,

0031 | MySQL: my.cnf

Tuesday, September 2nd, 2008 Posted in Database | 2 Comments »

เอามาเก็บไว้ฮะ สำหรับแรม 4gb ฐานข้อมูลขนาด 1 gb

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
set-variable=local-infile=0
skip-character-set-client-handshake
skip-name-resolve
skip-bdb
max_connections = 600
key_buffer = 512M
myisam_sort_buffer_size = 32M
join_buffer_size = 1M
read_buffer_size = 2M
sort_buffer_size = 4M
table_cache = 1536
thread_cache = 8
thread_concurrency = 4
thread_cache_size = 256
wait_timeout = 600
connect_timeout = 10
max_tmp_tables = 256
tmp_table_size = 64M
max_allowed_packet = 16M
max_connect_errors = 10
query_cache_limit = 1M
query_cache_size = 32M
query_cache_type = 1
query_prealloc_size = 16384
query_alloc_block_size = 16384
log_slow_queries
log_queries_not_using_indexes

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
open_files_limit = 8192

Tags: , ,