php扩展多进程共享内存
步骤:
1.运行命令:./ext_skel --extname=sharemem
2.运行命令:./configure --with-php-config=/usr/local/lnmp/php/bin/php-config
3.make clean
make
make install
/usr/local/lnmp/php/sbin/php-fpm restart
/usr/local/lnmp/php/bin/php-cgi /data0/htdocs/blog/sharemem.php
代码如下:
1.config.m4
PHP_ARG_ENABLE(sharemem, whether to enable sharemem support,
Make sure that the comment is aligned:
[ --enable-sharemem Enable sharemem support])
if test "$PHP_SHAREMEM" != "no"; then
PHP_NEW_EXTENSION(sharemem, sharemem.c, $ext_shared)
fi
2.php_sharemem.h
#ifndef PHP_SHAREMEM_H
#define PHP_SHAREMEM_H
extern zend_module_entry sharemem_module_entry;
#define phpext_sharemem_ptr &sharemem_module_entry
#ifdef PHP_WIN32
#define PHP_SHAREMEM_API __declspec(dllexport)
#else
#define PHP_SHAREMEM_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
/*hanhhh*/
#include "sys/mman.h"
#include "fcntl.h"
#include "semaphore.h"
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
/*hanhhh*/
typedef struct php_shared_mm {
sem_t mutex; /* the mutex: a Posix memory-based semaphore */
int count; /* and the counter */
} php_shared_mm;
PHP_MINFO_FUNCTION(sharemem);
PHP_FUNCTION(say8_count_add); /* For testing, remove later. */
PHP_FUNCTION(say8_count_dec); /* For testing, remove later. */
#endif /* PHP_SHAREMEM_H */
3.sharemem.c
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_sharemem.h"
zend_function_entry sharemem_functions[] = {
PHP_FE(say8_count_add, NULL)
PHP_FE(say8_count_dec, NULL)
{NULL, NULL, NULL} /* Must be the last line in sharemem_functions[] */
};
/* }}} */
/* {{{ sharemem_module_entry
*/
zend_module_entry sharemem_module_entry = {
#if
相关文档:
这次我们讲如何用PHP创建数据库以及表,和保存相关配置
先创建一个页面,用来输入相关信息
表单动作为 CreateData.php ,保存为Install.html (因为没有用到PHP,所以可以保存为HTML格式)
然后创建一个PHP文件,保存为CreateData.php ,用来创建数据库和保存相关信息
<?php
if(file_exists("Config.php"))
......
声明(本文转载自):http://www.phpzc.com/read.php?tid=643
ltrim();//去掉字符串左空格;
rtrim();//去掉字符串右空格;
trim(); //去掉字符串两边空格;
//去掉空格是返回一个新的字符串;原字符串不变;
strlen(); //计算字符串长度;
......
手册的官方地址: http://us3.php.net/manual/en/book.tokyo-tyrant.php
具体内容如下:
TCT支持的追加参数:
mode:
bnum: 桶数组元素个数,如果不大于0,使用默认值, 默认值是131071, 建议值是所有存储的记录条数的0.5-4倍.
apow: 和一个key关联的记录数,如果是负值, 使用默认值, 默认值为4, 意为2的4次方.
fpow: FreeBl ......
使用java中的动态代理可以完成很多事情,比如将业务实例进行托管,实现AOP等,但是Php中没有实现这样的东西,昨天突然想到其实可以通过eval来模拟一个动态代理机制。php比java不同的是,php是不需要编译的,因此只要我们能够动态生成一段代码,然后用eval来执行就可以达到效果。代码如下:
/**
* 代理实现类
*/
inter ......