Tag Archive for 'PHP'

Page 3 of 5

Kohanaphp新版本发布

Kohanaphp Framework

Kohanaphp Framework

Kohanaphp是一个基于CodeIgniter的PHP框架,继承了CI的优点:简洁、高效。与CakePHP不同的是,Kohanaphp尽可能的把事情做的简单,但却比CI做得更让开发者更友好,至少对于新手来说是这样的。现在这三者的速度是CI最快,但是功能最少,CakePHP最慢,但是功能强大,Kohanaphp则是在她们中间,更偏向与CI,因为其本身就是CI的衍生版本。

对于想快速开发小型项目或者是在线互动很小的项目。Kohanaphp一定是你最想要的PHP框架,忘记CakePHP的繁琐吧,忘记CI的过于简单,忘掉FleaPHP的本地化支持,你需要象Kohanaphp这样的框架,她做了你不想做了,把你自己想做的交给你。

Faster and faster, It’s all.

Share

使用自由软件测试HTTP服务

一个测试HTTP服务器极限的好方法就是模拟高负载下的HTTP服务器, 有5款自由软件是您的最好选择: curl-loader, httperf, Siege, Tsung, and Apache JMeter.

  • httperf
    测试5000次连接,每次50个请求

    1
    httperf --server=localhost --uri=/ --num-conns=5000 --num-calls=50

    高级应用

    1
    2
    3
    httperf --client=0/1 --server=localhost --port=80 --uri=/ \
    --send-buffer=4096 --recv-buffer=16384 \
    --num-conns=5000 --num-calls=50

    你也可以尝试一下一个更简单的类httperf软件http_load.

  • Siege
    和httperf类似, 上手非常简单

    1
    siege localhost

    利用sproxy连接代理服务器

    1
    sproxy -v -o urls.txt

    使用代理服务器

    1
    siege -v --internet --file=urls.txt

参考文章: http://www.linux.com/feature/143896

Share

提高mysql随机查询的效率

  1. 基本使用:
    1
    SELECT * FROM `table` ORDER BY RAND() LIMIT 0,10;

    但是在ORDER BY后面用到RAND(),查询速度非常慢.

  2. MAX()*RAND()提高效率
    1
    2
    3
    SELECT * FROM `table`
    WHERE id >= (SELECT floor( RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`)) + (SELECT MIN(id) FROM `table`)))
    ORDER BY id LIMIT 1;
  3. JOIN
    1
    2
    3
    4
    SELECT *
    FROM `table` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`))+(SELECT MIN(id) FROM `table`)) AS id) AS t2
    WHERE t1.id >= t2.id
    ORDER BY t1.id LIMIT 1;

Continue reading ‘提高mysql随机查询的效率’

Share

PHP配合Squid缓存动态页面Header写法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function nocache_headers() {
       // @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
       // @ header('Expires: Wed, 11 Jan 2009 05:00:00 GMT');  
       @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
       if(PAGEME=="bookinfo"){
                @ header('Expires: ' . gmdate ("D, d M Y H:i:s", time() + 3600*24). " GMT");
       }else{
                @ header('Expires: ' . gmdate ("D, d M Y H:i:s", time() + 3600). " GMT");      
       }
       
       // @ header('Cache-Control: no-cache, must-revalidate, max-age=0');
       // @ header('Pragma: no-cache');
               
       // @ header('Cache-Control: no-cache, must-revalidate, max-age=0');
       // @ header('Pragma: no-cache');
}
Share

PHP header work with Squid cache server

1
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

对于动态页面,则可以直接通过写入HTTP返回的头信息,比如对于新闻首页index.php可以是20分钟,而对于具体的一条新闻页面可能是1天后过期。比如:在php中加入了1个月后过期:

1
2
// Expires one month later
header("Expires: " .gmdate ("D, d M Y H:i:s", time() + 3600 * 24 * 30). " GMT");
Share

取消某个目录的PHP运行权限

1
2
3
4
RemoveHandler .cgi
RemoveHandler .php
RemoveHandler .pl
RemoveHandler .py

.htaccess 中或者是 httpd.conf 配置中设定就可以了。

Share

检查客户端浏览器和操作系统PHP脚本

使用方法:

1
2
3
4
5
6
<?php
echo ( browser_detection( 'number' ) .'<br>'.
browser_detection( 'browser' ) .'<br>'.  
browser_detection( 'os' ) .'<br>'.  
browser_detection( 'os_number' ) );
?>

Outputs (browser version, browser, os, os number):

1.5
moz
nt
5.1

1
2
3
4
5
6
7
8
9
10
<?php
if ( ( browser_detection( 'browser' ) == 'ie' )
&&
( browser_detection( 'number' ) >= 5 ) )
{
echo 'it is Internet Explorer ' .
browser_detection( 'number' );
// or anything else you want to happen of course
}
?>

下载:
browser_detection_php_ar.txt

原文地址:
http://techpatterns.com/downloads/php_browser_detection.php

Share

PHP script highcoloring with trac on dreamhost

因为在dreamhost 默认PATH的PHP4是cli编译的,就是CGI方式,所以PHP的语法高亮不能显示,在安装了silvercity之后也不能,需要将 trac.ini 中这样设置

1
php_path = /usr/bin/php -q

就可以了,关于这个主题的讨论可以看看这里

Share

MySQL error connections

连接MySQL得到这样的错误提示

1
Warning: mysql_pconnect(): Host '67.19.xx.xxx' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts' in C:\Websites\ratedesi\include\connectdb.php on line 9 Host '67.19.xx.xxx' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts'

在MySQL手册中找到这样的说明

A.2.5 `Host ‘HOST_NAME’ is blocked’
————————————
If you get the following error, it means that `mysqld’ has received
many connect requests from the host `’HOST_NAME that have
been interrupted in the middle:

Host ‘HOST_NAME’ is blocked because of many connection errors.
Unblock with ‘mysqladmin flush-hosts’

The number of interrupted connect requests allowed is determined by
the value of the `max_connect_errors’ system variable. After
`max_connect_errors’ failed requests, `mysqld’ assumes that
something is wrong (for example, that someone is trying to break
in), and blocks the host from further connections until you execute
a `mysqladmin flush-hosts’ command or issue a `FLUSH HOSTS’
statement. See *Note server-system-variables::.

By default, `mysqld’ blocks a host after 10 connection errors. You
can adjust the value by starting the server like this:

shell> mysqld_safe –max_connect_errors=10000 &
If you get this error message for a given host, you should first
verify that there isn’t anything wrong with TCP/IP connections from
that host. If you are having network problems, it does you no good
to increase the value of the `max_connect_errors’ variable.

这可能是比如PHP的未注销连接引起,查看MySQL的进程可以查看一下

1
 mysqladmin -u <user> -p<password> processlist
Share

一个错误,PHP

在使用cakephp的时候把项目转移到目的机器上,结果一直 start_session() 的错误,始终找不到原因,今天看看本地机器的 phpinfo() 结果发现少了 php.ini 加载。

加上之后, work fine.

Share