Monster Oasis
覺得累就是進步的開始!

2010/03/31

[php] array_key_exists vs isset 那一個比較快?

Filed under: Programming/php — Tags: — 12:56 pm

這些微差異要在大量的 loop 中才會有一些差別, 不過還是寫 code 時一次寫好吧 —> 給我自己的提醒!

答案是 isset 比較快!

ref. URL: http://www.alternateinterior.com/2006/11/comparing-array_key_exists-with-isset.html

相關資訊: A HOWTO on Optimizing PHP
http://phplens.com/lens/php-book/optimizing-debugging-php.php

Tuning Apache and PHP for Speed on Unix
http://phplens.com/phpeverywhere/tuning-apache-php

Related URL:
  1. [php] regular expression match
  2. USE Oracle / oci8 with PHP
  3. 範例程式 jQuery /JSON / PHP /json_encode / json_decode sample code
  4. PHP 小筆記
  5. opensolaris / Optimized Open Source Software Stack (Cool Stack)
  6. memcache sample code
  7. Protected: Senna for mysql install 安裝說明

2009/11/17

[php] regular expression match

Filed under: Programming/php — Tags: — 4:05 pm
preg_match( '/c=([0-9]+)/' , $t->log['dest_query'] , $data);
這樣可以取出 c=xxxx

抓 user agent 版本

preg_match( '/MSIE ([0-9]+.[0-9])/' , $_SERVER['HTTP_USER_AGENT'] , $data_msie_ver);
preg_match( '/Windows NT ([0-9]+.[0-9])/' , $_SERVER['HTTP_USER_AGENT'] , $data_nt_ver);
  if ( !( (float)$data_msie_ver[1]>=6 && (float)$data_msie_ver[1]<=8 ) ) $valid_useragent = 0;
Related URL:
  1. [php] array_key_exists vs isset 那一個比較快?
  2. USE Oracle / oci8 with PHP
  3. 範例程式 jQuery /JSON / PHP /json_encode / json_decode sample code
  4. PHP 小筆記
  5. opensolaris / Optimized Open Source Software Stack (Cool Stack)
  6. memcache sample code
  7. Protected: Senna for mysql install 安裝說明

2008/12/04

USE Oracle / oci8 with PHP

Filed under: Copy_N_Paste,DATABASE,Programming/php — Tags: , , — 1:17 pm

前提環境要先裝好 Oracle instant client , 然後 PHP 要把 instantclient 編譯進去

–with-oci8=instantclient,/usr/lib/oracle/10.2.0.3/client/lib

這是 sample code

$conn = OCILogon('scott', 'scott', '//172.30.0.176/DB1');

$query = 'select * from dept';

$stid = OCIParse($conn, $query);
OCIExecute($stid, OCI_DEFAULT);
while ($succ = OCIFetchInto($stid, $row)) {
  foreach ($row as $item) {
    echo $item." ";
  }
  echo "\n";
}

OCILogoff($conn);

心得是
1. 建 oracle table 時不管key 的 table name , field name 是否為小寫, 在 oracle 都顯示成大寫
2. 用 PHP 的 OCI functions 下的 SQL command 也可以不管大小寫
3.

Related URL:
  1. debian / ubuntu 裝 oracle instant client / sqlplus / oci8 / apache2 config / steps by steps

2008/09/17

範例程式 jQuery /JSON / PHP /json_encode / json_decode sample code

Filed under: Programming/javascript,Programming/php — Tags: , , , — 9:41 pm

jQuery : 請參考這篇 : http://jsgears.com/thread-63-1-1.html

Microsoft 也提供 video 教學: http://msdn.microsoft.com/zh-tw/asp.net/dd310332.aspx#jQuery

$(document).ready( function(){
  var data = new Object();
  data.hello = "Hello";
  data.world = 'World';
  data.worked = " it worked ";
  data.somebool = true;
  data.array = new Array("he\"ll\"o", '"World"');
  var dataString = $.toJSON(data);
  $.post('phpfile.php', {data: dataString}, function(res){
      var obj = $.evalJSON(res);
      if(obj.somebool === true)
      $("#result").html(obj.hello + ' ' + obj.array[1] + obj.worked + ". Message from PHP: "+obj.php_message);
    });
});

… 未完

Related URL:
  1. 颱風天在家練功 – CSS / jQuery

PHP 小筆記

Filed under: Programming/php — Tags: , , — 1:11 pm

[code language='php']
echo PHP_SAPI;
?>

[/code]

這個常數在 CLI mode 下是 cli
在 apache 下跑的話是 apache2handler

Related URL:
  1. Protected: 觀察 22:40 – 23:15 apache log 的變化
  2. 解決用 NFS 當 documentroot 時會當掉的方法
  3. debian / ubuntu 裝 oracle instant client / sqlplus / oci8 / apache2 config / steps by steps
  4. [ubuntu] apache server module 的 enable / disable
  5. apache Custom Log Formats – 好用的參數
  6. Simple Monster Tracking System – step by step
  7. Protected: apache mod_rewrite , rewrite , rewriterule 真難搞
  8. 好用的 iptables rules – 限制 client 連 http port 的次數
  9. Monster LAMP Pack Lite – ver.317
  10. 安裝 apache / mod_memcache

2008/08/04

opensolaris / Optimized Open Source Software Stack (Cool Stack)

看到一個有用的套件

for the Sun Solaris Operating System(TM)

http://cooltools.sunsource.net/coolstack/

Cool Stack includes several packages in the SVR4 package format, so you can install just the ones you need. Some of the applications in Cool Stack already ship with Solaris, but these are either older versions and/or not built with full optimization. Further, Cool Stack has been pre-configured to have the most popular applications (Apache, PHP, MySQL) to work seamlessly out of the box.
Deploying PHP From Cool Stack in Sun Java System Web Server

Configuring Cool Stack PHP With Web Server

Next, do the following:

1. Go to the Cool Stack PHP 5 installation location. Type:

cd /opt/coolstack/php5

In that directory is a script called setup-ws7-php.sh.

2. Run setup-ws7-php.sh. Type:

./setup-ws7-php.sh

This message is displayed:

Usage:
This script will configure Coolstack PHP with Sun Java System Web Server
7. Here, you will need to provide the top level location of your Web Server
7 installation and your Web Server 7 instance_name name to which this
script should configure to run PHP scripts.

Enter your Web Server installation location(/sun/webserver7):

3. Type the full path for your Web Server installation.

The script then prompts you to type a Web Server instance name. That name is the path to a directory in your installation location—one that contains all the configuration files for running your Web site. If you are using Web Server in Sun Java Enterprise System 5, your instances are under /var/opt/SUNWwbsvr7.

For the example in this article, cite the instance https-coolstack that you created previously. To enable a different instance for PHP, type that instance name. Your instance is then ready for PHP, which you can deploy with Cool Stack 1.2 PHP on Web Server.

Finally, do the following:

1. Start Web Server. Type:

/sun/webserver7/https-coolstack/bin/startserv

2. Create sample PHP files under /sun/webserver7/https-coolstack/docs.

Related URL:
  1. Protected: 觀察 22:40 – 23:15 apache log 的變化
  2. 解決用 NFS 當 documentroot 時會當掉的方法
  3. debian / ubuntu 裝 oracle instant client / sqlplus / oci8 / apache2 config / steps by steps
  4. [ubuntu] apache server module 的 enable / disable
  5. apache Custom Log Formats – 好用的參數
  6. Simple Monster Tracking System – step by step
  7. Protected: apache mod_rewrite , rewrite , rewriterule 真難搞
  8. 好用的 iptables rules – 限制 client 連 http port 的次數
  9. Monster LAMP Pack Lite – ver.317
  10. 安裝 apache / mod_memcache

2008/07/30

memcache sample code

Filed under: Programming/php — Tags: , — 6:20 pm

簡單版的測試 sample code

[code language='php']

// filename : memcache.php

$memcache = new Memcache;
$memcache->addServer('172.20.50.25', 11211);

// set 一個值到 memcache

$memcache->set('key', time() , MEMCACHE_COMPRESSED, 120);

// get 值

$data=$memcache->get('key');
print_r($data);

2008/07/23

Protected: Senna for mysql install 安裝說明

This post is password protected. To view it please enter your password below:


Related URL:
  1. Protected: emerge 不見的救法
  2. gentoo emerge command
  3. [gentoo] 排除舊的 lib 相容問題
  4. [monster] monster.tw 記錄 / memo / ubuntu / 裝 圖形介面 / GUI / gnome desktop / ip address / setting
  5. Protected: 兩個版本的 Linux ( CENTOS vs GENTOO ) 作 mysql + senna small compare
  6. gentoo linux ifconfig
  7. 查主機溫度
  8. 裝新的 www.monster.com.tw 過程記錄
  9. 在 gentoo 裝 oracle sqlplus package
  10. gentoo NFS

www.monster.com.tw , © Copyright 2008