多IP应用
Posted by Albert in PHP语言学习, linux 服务器安装 on July 9th, 2010
| 可以加一条指定源地址的路由来试试: 假定 指定使用1.1.1.2地址, 其所在的子接口为eth1:0 则 route add <目标网段/主机> gw <网关> dev eth1:0 如果是多网卡绑同网段ip也一样, 将dev后面的eth1:0换成 eth1 (假定1.1.1.2绑在eth1网卡上). |
运用header 让php程序被浏览器缓存
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && (time()-strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) < 3600*24)) {
header(“HTTP/1.1 304 Not Modified”);
exit;
}
header(“Last-Modified: ” . gmdate(‘D, d M Y H:i:s \G\M\T’, time()) );
expires:不大好用,直接敲还是会访问,这个虽然占服务器连接,但是至少他304,后面的不执行了。
过滤掉array中的空字串 php函数
array_filter(array(’2356′,”,’235′,’677′), ‘strlen’);
空会被过滤,剩下2356 235和677
php 函数处理相对目录和绝对目录混合目录
function getAbsolutePath($path) {
$path = str_replace(array(‘/’, ‘\\’), DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), ‘strlen’); //过滤掉空。。
$absolutes = array();
foreach ($parts as $part) {
if (‘.’ == $part) continue;
if (‘..’ == $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
return DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $absolutes);
}
php打开报错
error_reporting(E_ALL);
ini_set(“display_errors”, 1);
linux服务器查看cpu 内存相关信息
Posted by Albert in PHP语言学习, linux 服务器安装 on June 1st, 2010
转帖:
测试机器的硬件信息:
查看CPU信息(型号)
# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
8 Intel(R) Xeon(R) CPU E5410 @ 2.33GHz
(看到有8个逻辑CPU, 也知道了CPU型号)
Read the rest of this entry »
php 直读post主体数据
A quick tip for reading raw http POST data in PHP. For example if we have a xml posted to a page, we can read the raw data with the following code.
$xml = file_get_contents('php://input');
|
We could use $HTTP_RAW_POST_DATA instead, but many times it does not work due to some php.ini settings. Note that ‘php://input’ does not work with enctype=”multipart/form-data”.
php oci8 oracle连接池(11g) drcp
一个关于drcp的文档http://www.docin.com/p-5599651.html
使用 Oracle 数据库 11g 连接池
Oracle 数据库 11g 包含一个专门针对需要高可扩展性的应用程序的新特性:数据库驻留连接池 (DRCP)。通过 DRCP,我们可以在不同应用程序进程间共享数据库连接,从而更高效地使用服务器资源并全面提升吞吐量。Zend Server 随附的 PHP OCI8 扩展(目前为 V1.3.5)包含对 DRCP 的即用支持,使开发人员可以立即在其 PHP 应用程序中使用该特性。有关 PHP 和 DRCP 的更多详细信息,请参阅此处。
要在 Oracle 中启用 DRCP,登录到数据库服务器并启动连接池:
shell> sqlplus / as sysdba SQL*Plus: Release 11.1.0.6.0 - Production on Tue May 26 14:24:13 2009 Copyright (c) 1982, 2007, Oracle. All rights reserved. Connected to: Oracle Database 11g Release 11.1.0.6.0 - Production SQL> execute dbms_connection_pool.start_pool(); PL/SQL procedure successfully completed.
通过查询特定的 DBA_CPOOL_INFO 视图确认该池已启动:
SQL> SELECT CONNECTION_POOL, STATUS, MAXSIZE 2 FROM DBA_CPOOL_INFO; CONNECTION_POOL STATUS MAXSIZE ---------------------------------------------------------- SYS_DEFAULT_CONNECTION_POOL ACTIVE 40
然后,在 Zend Server 管理控制台的 Server Setup → Directives 页面,找到 OCI8 部分并在 oci8.connection_class 变量中设置 PHP 应用程序所使用的 DRCP 连接类的名称。该用户选择的名称允许不同应用程序的池化服务器间的逻辑划分:
最后,通过向您的 oci_connect() 连接字符串中添加关键字 POOLED 使您的 PHP 应用程序使用 DRCP。虽然不是必需的,但要实现最大可扩展性,我们推荐您用 oci_pconnect() 函数替换 oci_connect() 函数。修改为使用 DRCP (drcp.php) 之前的示例如下:
<html>
<head>
<style type="text/css">
table { border-collapse: collapse; }
td { border: solid 1px black; padding: 3px; }
</style>
</head>
<body>
<h2>Cities</h2>
<?php
// open database connection
$db = oci_pconnect('john', 'doe', '//achilles/orcl:POOLED');
if (!$db) {
trigger_error('Unable to connect to database', E_USER_ERROR);
}
// formulate and parse query
$sql = 'SELECT * FROM CITIES';
$stmt = oci_parse($db, $sql);
// execute query
oci_execute($stmt);
// iterate over result set
$count = 0;
echo '<table>';
while ($row = oci_fetch_object($stmt)) {
echo '<tr>';
echo '<td>' . $row→CITY_ID . '</td>';
echo '<td>' . $row→CITY_NAME . '</td>';
echo '</tr>';
$count++;
}
echo '</table><br/>';
echo $count . ' record(s) found.';
// close connection
oci_free_statement($stmt);
oci_close($db);
?>
</body>
</html>
唯一的更改是连接调用。无需更改应用程序。您还可以指定服务器连接通过 $ORACLE_HOME/network/admin/tnsnames.ora 文件进行汇集,如以下示例所示:
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = achilles)(PORT = 1521))
(CONNECT_DATA =
(SERVER = POOLED)
(SERVICE_NAME = orcl)
)
)
您的连接调用将如下所示:
$db = oci_pconnect('john', 'doe', 'ORCL');
注意,DRCP 不能在尚无 Oracle 11g 库的 Mac OS X 中使用,而且在任何情况下,Zend Server 的商业版在 Mac OS X 上都不受支持。
自己写的jsonServer jsonClient
-
<?php
-
/**
-
* 调用TEA加密算法,对所有Service目录下的类,都实例化之后调用。
-
* @author 肖江
-
* @filesource service/0
-
* @classname Json Server调用
-
* @copyright 2010-2-4
-
*/
-
class SjsonServer {
-
function __construct() {
-
self::$jsonDecode=new Btea();
-
}
-
function setKeyPasswd($domain) {
-
self::$serverInfo[‘keyPasswd’]=l(‘FmyRpc’)->$domain;
-
self::$domain=$domain;
-
}
-
/**
-
* 设置class 供外部使用
-
* @author 肖江
-
* @param $class
-
* @return unknown_type
-
*/
-
function setClass($class) {
-
self::$myClass=$class;
-
return $this;
-
}
-
/**
-
* 主函数,由index调用。
-
* @author 肖江
-
* @param $className
-
* @return unknown_type
-
*/
-
function run($className) {
-
try {
-
$this->setClass($className);
-
$this->parseData($_REQUEST);
-
$GLOBALS[‘domain’]=self::$domain;
-
$classObject=new $className; //load
-
<a href="mailto:$result=@call_user_func_array(array($classObject,self::$serverInfo['method'">$result=@call_user_func_array(array($classObject,self::$serverInfo['method'</a>]), $param);
-
// $debug=new BdebugE();
-
// $debug->showErr('JsonServer 执行了.',$className."\r\n结果:\r\n".print_r($result,true),1);
-
} catch (dherror $err) {
-
}
-
}
-
/**
-
* 检查Data
-
* @author 肖江
-
* @param $data
-
* @return unknown_type
-
*/
-
function parseData($data) {
-
else $this->setKeyPasswd($data['Domain']);
-
else {
-
else self::$serverInfo['method']=$this->getMethod($data['Method'],$data['SecureData']);
-
}
-
}
-
/**
-
* 获取方法名
-
* @author 肖江
-
* @param $methodStr
-
* @return unknown_type
-
*/
-
function getMethod($methodStr,$secureCode) {
-
//$method=self::$jsonDecode->decrypt($methodStr,self::$serverInfo['keyPasswd']);
-
$this->error(‘数据校验不通过’,10060);
-
return $method[1];
-
}
-
/**
-
* 错误抛出
-
* @author 肖江
-
* @param $errStr
-
* @param $errCode
-
* @param $className
-
* @return unknown_type
-
*/
-
function error($errStr,$errCode) {
-
throw new dhError ( $errStr,$errCode,‘接口 :’.self::$myClass,1 );
-
}
-
}
-
-
<?php
-
/**
-
*
-
* @author 肖江
-
* @test
-
*/
-
class SjsonClient {
-
/**
-
* 构造函数
-
* @author 肖江
-
* @param $url
-
* @param $domain
-
* @return unknown_type
-
*/
-
function __construct($url,$domain) {
-
self::$jsonDecode=new Btea();
-
self::$curl=new Bcurl();
-
self::$baseInfo[‘url’]=$url;
-
self::$baseInfo[‘domain’]=$domain;
-
self::$baseInfo[‘keyPasswd’]=l(‘FmyRpc’)->$domain;
-
self::setArrMode();
-
$this->error(‘未能找到相关网站密码’,10035,$url);
-
}
-
/**
-
* 设置client返回的是obj还是array
-
* @author 肖江
-
* @param boolean true是array false是object
-
* @return unknown_type
-
*/
-
self::$baseInfo[‘arrMode’]=$mode;
-
return $this;
-
}
-
/**
-
* 内部函数
-
* @param string 函数名
-
* @param array 参数
-
*/
-
function __call($funcName,$param) {
-
try {
-
$callRequest=$this->makeCall($funcName,$param);
-
-
‘method’=>‘POST’,
-
‘post_fields’=>$callRequest
-
))->exec();
-
} catch (dhError $e) {
-
$e->showDebugE(); //处理showMode=1
-
$e->getMsg(); //处理showMode=0/2
-
}
-
}
-
/**
-
* 创建一次请求信息
-
* @author 肖江
-
* @param $funcName
-
* @param $param
-
* @return unknown_type
-
*/
-
function makeCall($funcName,$param) {
-
$callRequest[‘Domain’]=self::$baseInfo[‘domain’];
-
$callRequest[‘Data’]=json_encode($param);
-
return $callRequest;
-
}
-
/**
-
* 错误抛出
-
* @author 肖江
-
* @param $errStr
-
* @param $errCode
-
* @param $className
-
* @return unknown_type
-
*/
-
function error($errStr,$errCode,$className) {
-
throw new dhError ( $errStr,$errCode,$className,1 );
-
}
-
}
-
php oci8 connect自动转码
$conn = oci_connect(‘hr’, ‘welcome’, ‘localhost/XE’, ‘AL32UTF8′);
如果oracle是gbk的,这条语句会让所有utf8的数据进入的时候自动转码成gbk的,读出的时候自动转码成utf8的,相当智能!
java和php能共享的session(通过memcache)
用普通的memcache重写session 实际上是为了让session用json格式保存,好用java读取..
java只需要修改它的session程序,就可以做到java php session通用(相互无缝调取)了
不过要注意$id就是session_id是在php.ini中设置name 要和java统一。。否则还是没戏
nginx ip 传递给apache remote_add..
Posted by Albert in PHP语言学习, linux 服务器安装 on May 12th, 2010
serialize print_r json_encode比较
好吧,我承认我只是为了了解一下这3个函数的效率如何
Read the rest of this entry »
apache cassandra在php上的一些应用
Posted by Albert in PHP语言学习, linux 服务器安装 on May 9th, 2010
http://github.com/mjpearson/Pandra/downloads
Dependencies
* Cassandra >= 0.6
* Thrift Interface (tested cassandra.thrift and pre-generated files are packaged)
* PHP >= 5.3
* OSSP PHP-UUID module
– Optional
* Model Generation – syck yaml
* Caching – APC or Memcached (PECL)
* Logging – Syslog, Sendmail and FirePHP
http://incubator.apache.org/cassandra/
GraphicsMagick 安装使用
Posted by Albert in PHP语言学习, linux 服务器安装 on May 7th, 2010
淘宝用于图片resize和水印的工具不是imagemagick而是graphicsmagick,效率据说高一些,我们来试试
download : http://www.graphicsmagick.org/download.html
下载.tar.gz文件 Read the rest of this entry »
让apache支持shtml 文件(转)
介绍一下shtml和shtm
关于shtml,shtml是一种基于SSI技术的文件,也就是Server Side Include–SSI 服务器端包含指令,一些Web Server如果有SSI功能的话就会对shtml文件特殊招待,服务器会先扫一次shtml文件看没有特殊的SSI指令存在,如果有的话就按Web Server设定规则解释SSI指令,解释完后跟一般html一起调去客户端。
关于shtm,shtm与shtml的关系和htm与html的关系大致相似,这里就不多说了。
html或htm与shtml或shtm的关系是什么
html或者htm是一种静态的页面格式,也就是说不需要服务器解析其中的脚本,或者说里面没有服务器端执行的脚本,而shtml或者shtm 由于它基于SSI技术,当有服务器端可执行脚本时被当作一种动态编程语言来看待,就如asp、jsp或者php一样。当shtml或者shtm中不包含服务器端可执行脚本时其作用和html或者htm是一样的。
如何使你的Apache服务器支持SSI?
Apache默认是不支持SSI的,需要我们更改httpd.conf来进行配置。我这里以windows平台的Apache 2.0.x为例,打开conf目录下的httpd.conf文件,搜索“AddType text/html .shtml”,搜索结果:
# AddType text/html .shtml
# AddOutputFilter INCLUDES .shtml
把这两行前面的#去掉。
然后搜索“Options Indexes FollowSymLinks”
在搜索到的那一行后面添加“ Includes”
即将该行改变为 Options Indexes FollowSymLinks Includes
保存httpd.conf,重起apache即可。
到此我们就完成了对Apache SSI的设置

Recent Comments