首先xampp在httpd.conf里面配置禁止遍历整个文件系统,对文件系统的默认访问被禁止,保护服务器文件。原来配置如下:
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
但是如果要让虚拟主机能被访问,有两个解决办法:一个是在全局里将Deny from all改成Allow from all ,但是有没发起到保护文件的作用;另一个办法是在虚拟主机里面加代码,如下:
ServerAdmin webmaster@eachbrand.com
DocumentRoot D:\projects\eachbrand.com
ServerName www.eachbrand.com
##能通过多个域名访问
#ServerAlias eachbrand.com *.eachbrand.com
ErrorLog logs/www.eachbrand.com-error_log
CustomLog logs/www.eachbrand.com-access_log common
AllowOverride All
Order deny,allow
Allow from all
基于域名的虚拟主机规则
1.必须指定服务器IP地址(和可能的端口)来使主机接受请求,这个可以用NameVirtualHost指令来进行配置。如果服务器上所有的IP地址都会用到,你可以用"*"作为NameVirtualHost的参数。如果你打算使用多端口(如运行SSL)你必须在参数中指定一个端口号,比如"*:80"。
2.为每个虚拟主机建立
段
的参数与NameVirtualHost的参数必须是一样的(比如说,一个IP地址或"*"代表的所有地址)。在每个VirtualHost段中,至少要有一个ServerName指令来指定伺服哪个主机和一个DocumentRoot指令来说明这个主机的内容位于文件系统的什么地方。
3.取消中心主机, 如果你想在现有的web服务器上增加虚拟主机,你必须也为现存的主机建造一个
定义块。这个虚拟主机中ServerName和DocumentRoot所包含的内容应该与全局的ServerName和DocumentRoot保持一致。还要把这个虚拟主机放在配置文件的最前面,来让它扮演默认主机的角色。
示范代码:
NameVirtualHost *:80
## for mainhost
ServerName localhost:80
DocumentRoot "/xampp/htdocs"
## for virtualhost
ServerAdmin webmaster@kakapo.cn
DocumentRoot D:\projects\kakapo.cn
ServerName www.kakapo.cn
##能通过多个域名访问
#ServerAlias kakapo.cn *.kakapo.cn
ErrorLog logs/www.kakapo.cn-error_log
CustomLog logs/www.kakapo.cn-access_log common
更多虚拟主机的配置示例代码请访问:
http://www.toplee.com/manuals/apache/apache2/vhosts/examples.html
自 PHP 5.1.1 起定义有以下常量来提供标准日期表达方法,可以用于日期格式函数(例如 date())。
DATE_ATOM(string)
原子钟格式(如:2005-08-15T15:52:01+00:00)
DATE_COOKIE(string)
HTTP Cookies 格式(如:Mon, 15 Aug 2005 15:52:01 UTC)
DATE_ISO8601(string)
ISO-8601(如:2005-08-15T15:52:01+0000)
DATE_RFC822(string)
RFC 822(如:Mon, 15 Aug 2005 15:52:01 UTC)
DATE_RFC850(string)
RFC 850(如:Monday, 15-Aug-05 15:52:01 UTC)
DATE_RFC1036(string)
RFC 1036(如:Monday, 15-Aug-05 15:52:01 UTC)
DATE_RFC1123(string)
RFC 1123(如:Mon, 15 Aug 2005 15:52:01 UTC)
DATE_RFC2822(string)
RFC 2822(如:Mon, 15 Aug 2005 15:52:01 +0000)
DATE_RSS(string)
RSS(如:Mon, 15 Aug 2005 15:52:01 UTC)
DATE_W3C(string)
World Wide Web Consortium(如:2005-08-15T15:52:01+00:00)
比如,要输出一个RSS需要的日期格式,就可以用下面的代码简单实现:
echo date(DATE_RSS);
存储过程和函数是MySql5.0刚刚引入的。关于这方面的操作在PHP里面没有直接的支持。但是由于Mysql PHP API的设计,使得我们可以在以前的PHP版本中的mysql php api中支持存储过程和函数的调用。
在php中调用存储过程和函数的主要步骤
1。调用存储过程的方法。
a。如果存储过程有 IN/INOUT参数,声明一个变量,输入参数给存储过程,该变量是一对,
一个php变量(也可以不必,只是没有php变量时,没有办法进行动态输入),一个Mysql变量。
b。如果存储过程有OUT变量,声明一个Mysql变量。
mysql变量的声明比较特殊,必须让mysql服务器知道此变量的存在,其实也就是执行一条mysql语句。
输入 set @mysqlvar=$phpvar ;
c。使用mysql_query()/mysql_db_query()执行mysql 变量声明语句。
Mysql_query("set @mysqlvar【=$pbpvar】");
这样,在mysql服务器里面就有一个变量,@mysqlar。如果时IN参数,那么其值可以有phpar传入。
D。 如果时存储过程。
1。执行 call procedure()语句。
也就是mysql_query("call proceduer([var1]…)");
2. 如果有返回值,执行select @ar,返回执行结果。
Mysql_query("select @var)"
接下来的操作就和php执行一般的mysql语句一样了。可以通过mydql_fetch_row()等函数获得结果。
如果时函数。 直接执行 select function() 就可以了。
php调用mysql存储过程和函数的方法一:
$user=\"root\";
$password=\"11212\";
$db=\"samp_db\";
$dblink=mysql_connect($host,$user,$password)
or die(\"can't connect to mysql\");
mysql_select_db($db,$dblink)
or die(\"can't select samp_db\");
$res=mysql_query(\"set @a=$password\",$dblink);
$res=mysql_query(\"call aa(@a)\",$dblink);
$res=mysql_query(\"select @a\",$dblink);
$row=mysql_fetch_row($res);
echo $row[0];
php调用mysql存储过程和函数方法二:此方法需要db_mysqli.dll的支持!
调用带有select语句的存储过程就出现 PROCEDURE p can’t return a result set in the given context的错误。Google了半天,在mysql官网上找到一些说法,db_mysql的模块不支持存储过程调用,解决方法是用db_mysqli。测试了一下,果然可以了。
用法比较简单,没啥好说的,从网上copy一段代码吧:
$link = mysqli_connect(
'localhost', /* The host to connect to */
'root', /* The user to connect as */
'root', /* The password to use */
'db_name'); /* The default database to query */
if (!$link) {
printf(\"Can't connect to MySQL Server. Errorcode: %sn\", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = mysqli_query($link, \"call se_proc('crm')\")) {
/* Fetch the results of the query */
while( $row = mysqli_fetch_array($result) ){
echo ($row[0]. \"--------- SR. \" . $row[1] . \"
\");
}
/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}
/* Close the connection */
mysqli_close($link);
?>
URL:http://blog.iyi.cn/start/2007/10/php_libmysqlmysqlnd.html
mysql 发不了一个MySQL native driver for PHP - mysqlnd来替代php5/php6中自带的mysqli模块,该模块可以在这里下载到:
- Download php_mysqli.dll for PHP 5.2.1 (Windows)
- Download source code (tar.gz)
- SVN repository: http://svn.mysql.com/svnpublic/php-mysqlnd/
- SVN Web Interface: http://svn.mysql.com/fisheye/browse/php-mysqlnd
安装方法是用该模块替换原来的mysqli模块,或者编译php之前,将ext/mysqli目录替换掉,然后在php源代码根目录执行:buildconf --force
编译的时候加上 --with-mysqli --enable-mysqlnd即可。
官方描述的这个模块的主要优点是:
On the C-level mysqlnd uses many of the proven and stable PHP internal functions. All the code of the new driver is contained in the ext/mysqli source directory. There is no need to link any external libraries. Thus you neither need to install the MySQL client library to compile PHP with ext/mysqli support nor do you need to take care of versions. Compiling has been made easier.
mysqlnd使用了很多底层的php函数,所有最新的驱动都包含在内,编译的时候不需要再额外关联其他的库。所以编译php的时候不需要先装mysql,也不需要关心mysql版本。编译极大的简化。
并且mysqlnd的性能有很好的改善,也修复了一些原有bug,比如
- improved persistent connections
- mysqli_fetch_all()
- performance statistics call: mysqli_get_cache_stats(), mysqli_get_client_stats(), mysqli_get_connection_stats()
把memcache使用时的一些细节记录下来.
- memcache每一个item上限是1M,注意不要超出上限
- memcache本身并不支持namespace,但是可以通过一些手段模拟出namespace的效果来,见Memcache 中模拟 namespace
- 刚接触memcache的时候,可能会写出这样的代码来 CODE:
- $zhang = $memcache->get('key1');
- $li = $memcache->get('key2');
- $wang = $memcache->get('key3');
这种写法实际运行效果是
- get(key1) - 客户端发出请求 - 服务器端查询 - 客户端获取
- get(key2) - 客户端 - 服务器端 - 客户端
- get(key3) - 客户端 - 服务器端 - 客户端
- ...
如此一来,会有三次客户端和服务器端交互的过程。但是如果用批量查询的方法,就只有一次交互的过程。比如:
CODE:- $all = $memcache->get(array('key1', 'key2', 'key3'));
这样性能会有一些提升。对于其它程序语言来说,也封装了类似get_multi这样的方法。
- 从数据库从查询获得一个列表,放到memcache里面保存起来是一个不错的主意,但是不要忘记memcache有1m限制。如果列表太大,可以考虑把数据分割开来,然后用key序列来保存这个列表数据,比如event_0_500来保存前500行,用event_0_1000保存500-1000行,在获取的时候可以用前面说的批量get来一次性得到这个列表。
- 经常观察memcache的大小,以及命中率,方便调整缓存策略





