Below you will find pages that utilize the taxonomy term “PHP & MYSQL”
Using Redis.
Readis
Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
1.Installation
a.Mac OSX[
]1
b.Ubuntu
-> % sudo apt-get install redis-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libjemalloc1 redis-tools
The following NEW packages will be installed:
libjemalloc1 redis-server redis-tools
0 upgraded, 3 newly installed, 0 to remove and 84 not upgraded.
Need to get 410 kB of archives.
After this operation, 1,272 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/universe libjemalloc1 amd64 3.5.1-2 [76.8 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty/universe redis-tools amd64 2:2.8.4-2 [65.7 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty/universe redis-server amd64 2:2.8.4-2 [267 kB]
Fetched 410 kB in 2s (176 kB/s)
Selecting previously unselected package libjemalloc1.
(Reading database ... 300693 files and directories currently installed.)
Preparing to unpack .../libjemalloc1_3.5.1-2_amd64.deb ...
Unpacking libjemalloc1 (3.5.1-2) ...
Selecting previously unselected package redis-tools.
Preparing to unpack .../redis-tools_2%3a2.8.4-2_amd64.deb ...
Unpacking redis-tools (2:2.8.4-2) ...
Selecting previously unselected package redis-server.
Preparing to unpack .../redis-server_2%3a2.8.4-2_amd64.deb ...
Unpacking redis-server (2:2.8.4-2) ...
Processing triggers for man-db (2.6.7.1-1) ...
Processing triggers for ureadahead (0.100.0-16) ...
ureadahead will be reprofiled on next reboot
Setting up libjemalloc1 (3.5.1-2) ...
Setting up redis-tools (2:2.8.4-2) ...
Setting up redis-server (2:2.8.4-2) ...
Starting redis-server: redis-server.
Processing triggers for libc-bin (2.19-0ubuntu6) ...
Processing triggers for ureadahead (0.100.0-16) ...
stevelo@stevelo-pc [12:01:47] [~]
Using Twig with Phalcon PHP and kill it!!
Using Twig with Phalcon PHP.
Twig is a modern template engine for PHP.
Now we can Using Twig with Phalcon.
How to do:
1.Install Twing in library as git submodule.
git submodule add git@github.com:fabpot/Twig.git app/library/Twig
2.Install phalcon incubator in library as git submodule.
git submodule add git@github.com:phalcon/incubator.git app/library/incubator
Phalcon framework testing
luosteve@SteveMac [10:55:51] [~/tmp]
-> % git clone --depth=1 git://github.com/phalcon/cphalcon.git
Cloning into 'cphalcon'...
remote: Counting objects: 1437, done.
remote: Compressing objects: 100% (971/971), done.
remote: Total 1437 (delta 593), reused 799 (delta 352)
Receiving objects: 100% (1437/1437), 2.08 MiB | 792.00 KiB/s, done.
Resolving deltas: 100% (593/593), done.
Checking connectivity... done.
luosteve@SteveMac [10:56:01] [~/tmp]
-> % cd cphalcon/build
root@SteveMac [10:56:35] [~/tmp/cphalcon/build] [master]
-> # ./install
.
.
.
.
.
.
une=native -O2 -finline-functions -fomit-frame-pointer -fvisibility=hidden -o phalcon.la -export-dynamic -avoid-version -prefer-pic -module -rpath /Users/luosteve/tmp/cphalcon/build/64bits/modules phalcon.lo
gcc ${wl}-flat_namespace ${wl}-undefined ${wl}suppress -o .libs/phalcon.so -bundle .libs/phalcon.o -march=native -mtune=native
dsymutil .libs/phalcon.so || :
warning: no debug symbols in executable (-arch x86_64)
creating phalcon.la
(cd .libs && rm -f phalcon.la && ln -s ../phalcon.la phalcon.la)
/bin/sh /Users/luosteve/tmp/cphalcon/build/64bits/libtool --mode=install cp ./phalcon.la /Users/luosteve/tmp/cphalcon/build/64bits/modules
cp ./.libs/phalcon.so /Users/luosteve/tmp/cphalcon/build/64bits/modules/phalcon.so
cp ./.libs/phalcon.lai /Users/luosteve/tmp/cphalcon/build/64bits/modules/phalcon.la
----------------------------------------------------------------------
Libraries have been installed in:
/Users/luosteve/tmp/cphalcon/build/64bits/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
during execution
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /Users/luosteve/.phpbrew/php/php-5.5.10/lib/php/extensions/no-debug-non-zts-20121212/
Thanks for compiling Phalcon!
Build succeed: Please restart your web server to complete the installation
./install 27.78s user 3.81s system 99% cpu 31.690 total
Gearman 不一樣的用法~~
Gearman
你所知道的Gearman
可以導入大量數據、發送許多電子郵件、編碼視頻文件、挖據數據並構建一個中央日誌設施 — 所有這些均不會影響站點的體驗和響應性。可以並行地處理數據。而且,由於 Gearman 協議是獨立於語言和平台的,所以您可以在解決方案中混合編程語言。比如,可以用 PHP 編寫一個 producer,用 C、Ruby 或其他任何支持 Gearman 庫的語言編寫 worker。
你所應用Gearman[
]1
PHP extension Redis 安裝使用
PHP extension Redis 安裝使用
安裝 PHP extension for Redis 使PHP可以與Redis運作.
安裝
$ cd /tmp
$ git clone git://github.com/nicolasff/phpredis.git
$ cd /tmp/phpredis
$ phpize
$ ./configure
$ make
$ make install clean
#編輯 php.ini加入
extension=redis.so
Redis Key-Value資料庫建置實測
reids
Redis是一個開源的使用ANSI C語言編寫、支援網路、可基於記憶體亦可持久化的日誌型、Key-Value資料庫,並提供多種語言的API。從2010年3月15日起,Redis的開發工作由VMware主持。
通常,Redis將數據存儲於記憶體,或被配置為使用虛擬記憶體。通過兩種方式可以實現數據持久:使用快照的方式,將內存中的數據不斷寫入磁碟;或使用類似MySQL的日誌方式,記錄每次更新的日誌。前者性能較高,但是可能會引起一定程度的數據遺失(後者相反)。
Mac 使用brew安裝reids
-> % brew install redis
==> Downloading http://redis.googlecode.com/files/redis-2.4.8.tar.gz
######################################################################## 100.0%
==> make -C src
==> Caveats
If this is your first install, automatically load on login with:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/redis/2.4.8/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
If this is an upgrade and you already have the homebrew.mxcl.redis.plist loaded:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
cp /usr/local/Cellar/redis/2.4.8/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
To start redis manually:
redis-server /usr/local/etc/redis.conf
To access the server:
redis-cli
==> Summary
/usr/local/Cellar/redis/2.4.8: 9 files, 424K, built in 5 seconds
FuelPHP FrameWork 進入! Enter~~
安裝之前有說過哩:請參考 FuelPHP FrameWork 初體驗~~
之前說過 作者將APP 整個包在FrameWork 內的蠢話. 我可以不承認嗎XDD
其實算是給開發人員快速進入,實作體驗FrameWork用的.
如果要自行快速分離請先參考 同事強做:【程式筆記】建立一個FuelPHP的應用程式Git Repository
如果這樣不能滿足你,接下來江示範如何調整.
FuelPHP FrameWork 初體驗~~
FuelPHP is a simple, flexible, community driven PHP 5.3 web framework based on the best ideas of other frameworks with a fresh start.
FuelPHP 衝著他以php 5.3 並以namespace 方式開發,輕量化FrameWork趕快來試用看看吧.
安裝
安裝方式不免俗來了,快速按裝.(不錯唷)
$ curl get.fuelphp.com/oil | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 244 100 244 0 0 240 0 0:00:01 0:00:01 --:--:-- 1257
Password:
$
Gearman Install on Ubuntu
MongoDB Sharing
MongoDB Sharing[
]1
可以先看看官網介紹:Sharding Introduction
Shards 類似 Mysql 的Data nodes.
Config Servers 類似 Mysql 的Management node.
Routing Processes 類似 Mysql 的SQL node.
MongoDB VS Mysql 簡單測試.
廢話不多說.
MongoDB 使用 MongoDB Object Document Mapper測試.
Mysql 使用 Object Relational Mapper測試.
MongoDB部分:
config.php
register();
$classLoader = new ClassLoader('Doctrine\ODM\MongoDB', __DIR__ . '/../../lib');
$classLoader->register();
$classLoader = new ClassLoader('Doctrine\MongoDB', __DIR__ . '/../../lib/vendor/doctrine-mongodb/lib');
$classLoader->register();
$classLoader = new ClassLoader('Symfony', __DIR__ . '/../../lib/vendor');
$classLoader->register();
$classLoader = new ClassLoader('Documents', __DIR__);
$classLoader->register();
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(__DIR__ . '/Hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setDefaultDB('doctrine_odm_sandbox');
//使用safe模式
$con = new Connection('localhost',array('safe'=>true, 'w' => 2,'wtimeoutMS' => 2000));
//使用一般模式
//$con = new Connection('localhost');
$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\');
$config->setMetadataDriverImpl(new AnnotationDriver($reader, __DIR__ . '/Documents'));
$dm = DocumentManager::create($con, $config);
Lua for PHP 實測
繼上一篇 Lua for PHP 安裝,現在來是實測Lua 速度.
素聞Lua 執行效能速度之優異不論是陣列字串運算處理皆在PHP之上,這篇先主要針對Array做實測.
index.php
array_b = $array_b;
//測試PHP物件排序效能
$mtime = explode(' ', microtime());
$starttime = $mtime[1] + $mtime[0];
//var_dump($array_a);
rsort($array_a);
//var_dump($array_a);
$mtime = explode(' ', microtime());
$times=number_format(($mtime[1] + $mtime[0] - $starttime), 8);
//顯示PHP執行結果所需時間
echo "PHP rsort time $times \n";
$mtime = explode(' ', microtime());
$starttime = $mtime[1] + $mtime[0];
//var_dump($array_b);
//測試Lua物件排序效能
$array_b = $lua->test();
//var_dump($array_b);
$mtime = explode(' ', microtime());
$times=number_format(($mtime[1] + $mtime[0] - $starttime), 8);
//顯示Lua執行結果所需時間
echo "Lua array sort time $times \n";
test.lua
function test()
table.sort( array_b )
return array_b
end
MongoDB 新手入門筆記~
Lua for PHP 安裝
Zend Framework 1.11.0 and Doctrine 1.2.3 and Smarty 3.0.4
懶惰許久~~ 趕快來補一下功課.
這篇主要介紹 Zend Framework 1.11.0 and Doctrine 1.2.3 and Smarty 3.0.4 的結合方式.
Doctrine 1.2.3 跟 Zend Framework 1.11.0 結合主要參考 http://pastie.org/481633 http://pastie.org/481635 使用.
目錄結構:[
]1
FreeBSD 上使用 wkhtmltopdf 做網頁擷取
以往要用程式控制將網頁輸出pdf或擷取網頁,都是件浩大工程.
這次介紹如何在FreeBSD 命令列模式下即可輕易辦到,並且不需龐大的X Windows 圖形系統適合在server上跑.
以下是軟體原文介紹.
wkhtmltopdf
Convert html to pdf using webkit (qtwebkit)
Description
Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.
Introduction
Searching the web, I have found several command line tools that allow you to convert a HTML-document to a PDF-document, however they all seem to use their own, and rather incomplete rendering engine, resulting in poor quality. Recently QT 4.4 was released with a WebKit widget (WebKit is the engine of Apples Safari, which is a fork of the KDE KHtml), and making a good tool became very easy.
此軟體使用WebKit開發完成,除了flash以外其他接可正常顯示!!(包含js)
在安裝前請先確定你的FreeBSD已安裝 linux-base 套件並正常使用,並且將port tree更新.