mkdir /srv/php-5.2.17/etc/conf.d /srv/php-5.2.17/bin/phpize ./configure --with-php-config=/srv/php-5.2.17/bin/php-config make && make install
cat > /srv/php-5.2.17/etc/conf.d/sqlite.ini <<EOF extension=sqlite.so extension=pdo_sqlite.so EOF
mkdir /srv/php-5.2.17/etc/conf.d /srv/php-5.2.17/bin/phpize ./configure --with-php-config=/srv/php-5.2.17/bin/php-config make && make install
cat > /srv/php-5.2.17/etc/conf.d/mysqli.ini <<EOF extension=mysqli.so EOF
<?php $connection = new MongoClient( "mongodb://neo:chen@192.168.6.1" ); $db = $connection->test; $grid = $db->getGridFS(); $id = $grid->put("/etc/passwd");
<?php $connection = new MongoClient( "mongodb://neo:chen@192.168.6.1" ); $db = $connection->test; $grid = $db->getGridFS(); $id = $grid->put("/etc/passwd"); $oid = new MongoId($id); $file = $grid->get($oid); echo $file->getBytes();
storeFile 與 put 類似
<?php $connection = new MongoClient( "mongodb://neo:chen@192.168.6.1" ); $db = $connection->test; $grid = $db->getGridFS(); $storedfile = $grid->storeFile("/etc/passwd", array("date" => new MongoDate())); // Return newly stored file's Document ID echo $storedfile;
findOne 與 get 類似,get 只能通過id取出檔案,findOne可以查找檔案名,日期,尺寸,以及md5值。
<?php $connection = new MongoClient( "mongodb://neo:chen@192.168.6.1" ); $db = $connection->test; $grid = $db->getGridFS(); $file = $grid->findOne("/etc/passwd"); echo $file->getBytes();
指定 collections
<?php $images = $db->mydb->getGridFS('images'); $image = $images->findOne('jwage.png'); header('Content-type: image/png;'); echo $image->getBytes(); ?>
進入PHP工作目錄
cd /usr/local/php/
安裝 memcache
pecl install
pecl install memcache
php.ini memcache 參數
cat >> /srv/php/etc/php.ini <<EOF extension = memcache.so [memcache] memcache.allow_failover = 1 memcache.max_failover_attempts=20 memcache.chunk_size =8192 memcache.default_port = 11211 memcache.default_timeout_ms=30 EOF
$ sudo apt-get install php5-memcache
memcache.ini 檔案
$ cat /etc/php5/conf.d/memcache.ini ; uncomment the next line to enable the module extension=memcache.so [memcache] memcache.dbpath="/var/lib/memcache" memcache.maxreclevel=0 memcache.maxfiles=0 memcache.archivememlim=0 memcache.maxfilesize=0 memcache.maxratio=0
pecl install redis
php.ini
cat > /srv/php/etc/conf.d/redis.ini <<EOF extension=redis.so EOF
https://github.com/nicolasff/phpredis
yum search redis php-redis.x86_64 : Extension for communicating with the Redis key-value store python-redis.noarch : A Python client for redis redis.x86_64 : A persistent key-value database
安裝git版本控制客戶端
yum install git
從github倉庫中克隆一份代碼到本地
git clone git://github.com/nicolasff/phpredis.git
編譯安裝phpredis; 我暫時沒有找到 pecl的phpredis源
cd phpredis phpize ./configure --with-php-config=/srv/php-5.4.9/bin/php-config make && make install
創建配置檔案
cat > /srv/php-5.4.9/etc/conf.d/redis.ini <<EOF extension=redis.so EOF
查看安裝情況
# php -m | grep redis redis
使用 Redis 存儲 Session 數據
session.save_handler = redis session.save_path = "tcp://127.0.0.1:6379" 或者使用多個redis session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2"
auth 認證配置
session.save_handler = redis session.save_path = "tcp://redis.example.com:6379?auth=[AUTH_STRING_HERE]"
資料庫選擇
session.save_path = "unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0
Sql Server 支持由Freetds提供
cd /usr/local/src/ wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz tar zxvf freetds-stable.tgz cd freetds-0.64/ ./configure --prefix=/usr/local/freetds-0.64 make make install ln -s /usr/local/freetds-0.64 /usr/local/freetds
configure
./configure --prefix=/usr/local/php-5.2.3 \ --with-config-file-path=/usr/local/php-5.2.3/etc \ --enable-fastcgi \ --enable-force-cgi-redirect \ --with-curl \ --with-gd \ --with-ldap \ --enable-zip \ --enable-exif \ --enable-pcntl \ --with-mssql=/usr/local/freetds make make test make install
MSSQL在PHP中的配置如下
/usr/local/freetds/etc/freetds.conf
[MyServer2k] host = 10.10.10.11 port = 3433 tds version = 8.0
mssql.php 測試檔案
<?php $conn = mssql_pconnect('MyServer2k', 'u_mobile', 'kEyt+_Zf.$P6'); mssql_select_db('D3_Mobile', $conn); $query = mssql_query ('select * from dbo.MobileCommand where id=1'); $result = mssql_fetch_array ($query); echo '<pre>'; print_r($result); echo '</pre>'; ?>
mssql_pconnect | |
---|---|
resource mssql_connect ( [string servername [, string username [, string password [, bool new_link]]]] ) servername 指的是freetds.conf中定義伺服器名 |
測試
php -q mssql.phppdo_oci/oci8
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
export ORACLE_HOME=/usr/lib/oracle/11.1/client64/ export LD_LIBRARY_PATH=/usr/lib/oracle/11.1/client64:$LD_LIBRARY_PATH export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
cd /usr/local/src/php-5.2.14/ext/pdo_oci /usr/local/php-5.2.14/bin/phpize ./configure --with-php-config=/usr/local/php-5.2.14/bin/php-config --with-oci8=instantclient,/usr/lib/oracle/11.1/client64/lib make make install
安裝後生成/usr/local/php/lib/php/extensions/no-debug-non-zts-yyyymmdd/oci8.so 把oci8.so 移動到/usr/local/php/lib/php/extensions/目錄下 mv /usr/local/php/lib/php/extensions/no-debug-non-zts-yyyymmdd/oci8.so ../ extension_dir = /usr/local/php/lib/php/extensions/ 添加 extension = pdo_oci.so extension = oci8.so
例 5.3. oracle
ln -s /usr/lib/oracle/10.2.0.3/client64 /usr/lib/oracle/10.2.0.3/client ln -s /usr/include/oracle/10.2.0.3/client64 /usr/include/oracle/10.2.0.3/client export ORACLE_HOME=/usr/lib/oracle/10.2.0.3/client64/ export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client64:$LD_LIBRARY_PATH export NLS_LANG="AMERICAN_AMERICA.AL32UTF8" # /usr/local/php-5.2.14/bin/phpize # ./configure --with-php-config=/usr/local/php-5.2.14/bin/php-config --with-pdo-oci=instantclient,/usr,10.2.0.3 # make && make install
php.ini
extension=pdo_oci.so
oci.php
<?php $pdo= new PDO("oci:dbname=//localhost:1521/mydbname;charset=utf-8,username,password); $sql="select table_name as tname from user_tables"; $query = $pdo->prepare($sql); $query->execute(); for($i=0; $row = $query->fetch(); $i++){ #print_r($row); echo $i." - ".$row[0]."<br/>"; echo $i." - ".$row['TNAME']."<br/>"; } ?>