Joe Horn 的啟示錄
Joe Horn's Blog
  • About.me
  • Facebook
  • Flickr
  • GitHub
  • Instagram
  • LinkedIn
  • Pinterest
  • Slideshare
  • Twitter
  • YouTube
  • Tumblr
RSS
  • All Posts
  • VPS Referrals
  • My Plurk
  • My Plurk Bot

3 月 4 2015

勞保局的自然人憑證元件…

現在都什麼時候了… 是沒有人在用嗎? O_o

分享此文:

  • Tweet

By Joe Horn • Life, WWW

12 月 30 2014

Crucial M550 on Lenovo L412

從數據看來,也是受限於界面速度,但 4k 對齊與 AHCI 設定等等的 tuning 影響頗大。

調整前:

調整後:

4k-64Thrd 的寫入差距頗大…

分享此文:

  • Tweet

By Joe Horn • Computer Hardware • Tags: Crucial, L412, Lenovo, M550, SSD

12 月 14 2014

rsyslog daemon 在 OpenVZ guest 瘋狂佔用 CPU resource

剛幫忙解掉的問題。
某台建立在 OpenVZ 的 Ubuntu 的 rsyslog daemon process 瘋狂佔用 CPU resource。
log 看到的狀況是這樣:

...
Dec 14 06:25:13 Linux rsyslogd-2177: rsyslogd[internal_messages]: 1134916 messages lost due to rate-limiting
Dec 14 06:25:13 Linux rsyslogd: imklog: error reading kernel log - shutting down: Bad file descriptor
Dec 14 06:25:13 Linux rsyslogd: message repeated 498 times: [imklog: error reading kernel log - shutting down: Bad file descriptor]
Dec 14 06:25:19 Linux rsyslogd-2177: rsyslogd[internal_messages]: 1114295 messages lost due to rate-limiting
Dec 14 06:25:19 Linux rsyslogd: imklog: error reading kernel log - shutting down: Bad file descriptor
Dec 14 06:25:19 Linux rsyslogd: message repeated 498 times: [imklog: error reading kernel log - shutting down: Bad file descriptor]
Dec 14 06:25:25 Linux rsyslogd-2177: rsyslogd[internal_messages]: 1805432 messages lost due to rate-limiting
Dec 14 06:25:25 Linux rsyslogd: imklog: error reading kernel log - shutting down: Bad file descriptor
Dec 14 06:25:25 Linux rsyslogd: message repeated 498 times: [imklog: error reading kernel log - shutting down: Bad file descriptor]
...

把 /etc/rsyslog.conf 下列這行註解掉,重新啟動 rsyslog 就搞定了… :-)

$ModLoad imklog   # provides kernel logging support

分享此文:

  • Tweet

By Joe Horn • Linux • Tags: Linux, OpenVZ, rsyslog, Ubuntu

11 月 30 2014

[MySQL] shrink ibdata file

最近幫忙處理某台 MySQL 5.0 server,做了個小實驗,寫個文章把處理過程紀錄下來。

因為該 server 沒有 innodb_file_per_table 這個設定,所有的 InnoDB 資料都放在 ibdata 這個檔案裡,而我們希望能讓該 server 持續運作,盡可能在不停機的狀況下,把 InnoDB 的資料切開。

實驗後,我們透過這些步驟完成切割/轉移:

  1. 確認舊的 server 有開啟 binlog,準備跑 replication。
  2. 用 Percona XtraBackup 備份舊的 MySQL 資料庫。
  3. 準備新機器,把備份檔丟到新的 server。
  4. 在新機器的 my.cnf 加入 innodb_file_per_table 設定,把 MySQL daemon 跑起來。
  5. 在新機器用以下指令把 InnoDB table 挑出來:
    SELECT `TABLE_SCHEMA`, `TABLE_NAME` FROM `TABLES` WHERE `ENGINE`='InnoDB' ORDER BY `TABLE_SCHEMA`,`TABLE_NAME`;
  6. 在新機器用 mysqldump 匯出 table schema & data :
    mysqldump -u root -pMY_PASSWORD --max_allowed_packet=512M -Cx --opt TABLE_SCHEMA TABLE_NAME > TMP_DIR/TABLE_SCHEMA.TABLE_NAME.sql
  7. 在新機器 drop 掉已匯出的 table:
    DROP TABLE `TABLE_SCHEMA`.`TABLE_NAME`;
  8. 停掉新機器的 MySQL daemon,把 datadir 的 ib* 搬走,再啟動 MySQL daemon。
  9. 重新匯入 table:
    mysql -u root -pMY_PASSWORD TABLE_SCHEMA < TMP_DIR/TABLE_SCHEMA.TABLE_NAME.sql
  10. 用 CHANGE MASTER TO … 指令開始讓新機器的 MySQL 成為舊 server 的 SLAVE。
  11. 同步完成後,找時間讓舊的 server 退下,讓新的 server 佔用舊機器的 IP。
  12. 在新機器的 MySQL 執行 RESET SLAVE,停掉 replication。

分享此文:

  • Tweet

By Joe Horn • Database • Tags: ibdata, innodb_file_per_table, MySQL, mysqldump, shrink, XtraBackup

7 月 10 2014

[PHP] 自製金錢分攤函式

近日在工作上應該會需要計算金錢分攤,簡單寫了個 PHP 函式備用。

function shareAmount( $amount , $shares ) {
    $arr = array();
    if ( is_numeric($amount) && is_int($shares) ) {
        $precision = is_int($amount) ? 0 : strlen(substr($amount, strpos($amount, '.')+1));
        for ( $i = $shares; $i > 0; $i-- ) {
            $val = round( $amount / $i , $precision );
            array_push( $arr , $val );
            $amount -= $val;
        }
    }
    return $arr;
}

執行結果大概像這樣:

// var_dump( shareAmount(101,3) );
array(3) {
  [0]=>
  float(34)
  [1]=>
  float(34)
  [2]=>
  float(33)
}

// var_dump( shareAmount(0.5101,3) );
array(3) {
  [0]=>
  float(0.17)
  [1]=>
  float(0.1701)
  [2]=>
  float(0.17)
}

我在資料庫沒看到大數,所以就沒考慮 BC Math,直接用 is_numeric() 了… :p

分享此文:

  • Tweet

By Joe Horn • PHP • Tags: PHP

5 月 4 2014

Javascript 的變數範圍

最近在微調部門某個 PHP 專案程式,該專案使用 ExtJS 作前端介面 framework …
整理這個專案內的 Javascript 程式讓我覺得… 應該有不少人忽略,或是不在意 Javascript 的變數定義方式。

先來看這串程式碼:

執行結果:

這張圖有趣就在第 40, 41 行程式碼執行的結果差異,以及 42, 43 行程式碼執行的結果差異。
在 Javascript 不透過 var 進行定義之變數,皆為全域變數;但透過 var 定義之變數就有變數範圍。
這兩種變數定義方式影響瀏覽器開啟網頁後的記憶體耗用量,以及 Javascript engine 進行 GC 的效率與結果,不得不慎呀…

分享此文:

  • Tweet

By Joe Horn • Javascript • Tags: Garbage collection, GC, Javascript, variable scope

3 月 4 2014

Sencha Touch 使用心得

這陣子在進行一個 mobile web 開發專案;我們對 Ext JS 還算熟悉,故選擇採用同公司的產品:Sencha Touch。
我們沒使用過,決定先進行 prototyping,看能挖出多少可用、好用的元件。
目前第一版趨近完成,我先寫篇心得分享,順道幫自己留個筆記;請路過看到的前輩、高手們不吝給予指教啦~ (羞)

目前是 2014 年 3 月初,已釋出的 Sencha Touch 最新 GPL 版本是 2.3.1,但堪用的是 2.1.1。
Sencha Touch 僅支援 WebKit based 網頁瀏覽器,大致上就是這些。

More

分享此文:

  • Tweet

By Joe Horn • Javascript • Tags: Ext.field.DatePicker, Ext.MessageBox, Ext.Msg, Sencha Touch

2 月 22 2014

[Apache Tomcat] Enhance security

我沒有在使用 Apache Tomcat 的後台,佈署軟體/程式都是透過 scp/sftp/ftp 等方式做傳輸。
所以在解開 Apache Tomcat 的壓縮檔之後,我會執行以下指令,把不必要的檔案清掉,增強安全性:

cd apache-tomcat-* && \
/bin/rm -rf webapps/docs webapps/examples webapps/host-manager webapps/manager && \
/bin/rm -f webapps/ROOT/*.gif webapps/ROOT/*.xml webapps/ROOT/*.ico webapps/ROOT/*.txt webapps/ROOT/*.svg && \
/bin/cat /dev/null > webapps/ROOT/index.jsp &&
/bin/cat /dev/null > webapps/ROOT/index.html

分享此文:

  • Tweet

By Joe Horn • Computer Software • Tags: Apache Tomcat, security

2 月 14 2014

[實測] Plextor M5M 256GB mSATA SSD (PX-256M5M) on Lenovo T420s

前幾天幫我在家用的 Lenovo T420s 裝上新的 mSATA SSD,用 AS SSD Benchmark 跑了些數據,貼在這裡做個紀錄。

受限於 T420s 的介面速度,Plextor M5M 256GB mSATA SSD 的效能沒有完全發揮。

對照組,T420s 原廠給的 7mm 2.5″ 7200rpm HDD。

雖然 SSD 的效能沒有完全發揮,用來當系統碟的爽度依然很高啊… 8-)

分享此文:

  • Tweet

By Joe Horn • Computer Hardware • Tags: Lenovo, M5M, mSATA, Plextor, SSD, T420s

9 月 27 2013

[PHP] HTTP 連線的資料共用

我相信有許多 Web 應用程式開發者與我類似,常常想辦法預存一些經常存取、變動頻率不高的資料,提昇程式效能。
透過這類的資料預存,可以降低資料庫存取頻率,並減少 server 的 file I/O 次數。

在 .Net 與 JAVA 的領域,程式語言都提供了相關的物件/變數,讓 Web 應用程式儲存資料,而該應用程式的所有連線使用者皆可以存取。
.Net 用的是 System.Web.Caching.Cache;JAVA Servlet 是 javax.servlet.ServletContext,而 JSP 的 Application 物件便是其實作。
但在常見的環境(eg. Apache HTTPD w/MPM prefork + mod_php),也沒有額外的模組(eg. APC、memcache),PHP 難以提供這種物件/變數讓人使用,開發者只能硬幹。 :p

因為 COOKIE 的 size 有限,在 PHP 大概只能用 SESSION 硬幹。
我是這樣做的…

存入/更新:

function writeAppCache( $app_name , $data ) {
    // 紀錄原本的 session ID
    $orig_session_id = session_id();

    // 如果已有 session 存在
    if ( !empty($orig_session_id) ) {

        // 存放原本的 session 資料
        session_write_close();

        // 切換到自己定義的 application session,存放/更新資料
        session_id($app_name);
        $_SESSION = $data;
        session_write_close();

        // 切換回原本的 session
        session_id($orig_session_id);
        session_start();
    }
}

讀取:

function readAppCache( $app_name ) {
    $data = null;
    // 紀錄原本的 session ID

    $orig_session_id = session_id();
    // 如果已有 session 存在
    if ( !empty($orig_session_id) ) {

        // 存放原本的 session 資料
        session_write_close();

        // 切換到自己定義的 application session,讀取資料
        session_id($app_name);
        $data = $_SESSION;
        session_write_close();

        // 切換回原本的 session
        session_id($orig_session_id);
        session_start();
    }
    return $data;
}

因為所有程式都能存取 session 內的資料,不建議在 session 內儲存私密/機密資料。
若要避免資料不小心被同一台 server 的其他程式,可以加上 session_name() 作區隔。

分享此文:

  • Tweet

By Joe Horn • PHP • Tags: javax.servlet.ServletContext, performance, PHP, session, System.Web.Caching.Cache

«‹ 2 3 4 5 ›»

Site Info

本站小貼紙
本站小圖
There are lots of zh_TW words encoded with UTF-8 in this Blog.
創用 CC 授權條款
本站所有內容係採用創用 CC Attribution-NonCommercial-NoDerivatives 4.0 國際 授權條款授權.

About me

profile for Joe Horn at Stack Overflow, Q&A for professional and enthusiast programmers

My mail!

獅子座

Coffee Powered!

F1 fans

motoGP fans

Linkin Park

I am a Taiwanese!

Recent Comments

  • Avatar of johnpupu johnpupu: PHP 還有這個 phpsavant.c……
  • Avatar of Jerry Jerry: 这个不是foreach的问题。 0 ==……
  • Avatar of Joe Horn Joe Horn: 看來問題在 if ... else ..……
  • Avatar of jnlin jnlin: 因為 'b' 被轉型成 0 了…
  • Avatar of 路人 路人: 跟 foreach 沒有關係 ?…
  • Avatar of bill bill: 註冊表那裡要設定 BasicAuthLe……
  • Avatar of 虫 虫: .svn 的檔案減少可以增加在 wind……
  • Avatar of mars mars: 如果說寫程式是理性極致的話,那寫小說就是……
  • Avatar of Joe Horn Joe Horn: 已更新文章。…
  • Avatar of jackcal jackcal: joehorn.idv.tw關於轉貼 h……

Post Categories

  • About My Sites (16)
  • Computer Hardware (24)
  • Computer Software (45)
  • Database (20)
  • FreeBSD (21)
  • Funny (14)
  • Life (23)
  • Linux (4)
  • Mail (19)
  • Network (11)
  • Programing (40)
    • .NET (5)
    • JAVA (2)
    • Javascript (6)
    • PHP (29)
  • Thoughts (34)
  • Windows (13)
  • WWW (78)
    • phpBB (7)
    • WordPress (18)

Blogroll

  • ケロン軍團戰略室 (INGRESS)
  • 這裡沒有美食
  • 哈寶的 Blog
  • DK Moto Club
  • RB susu 的 Blog
  • 日落的 Blog
  • 小恬的 Blog
  • 小麻的 Blog
  • Huckly 的 Blog
  • ziway 的 Blog

Tags Cloud

AMD Apache Bloglines C# Coppermine DNSBL domain name eAccelerator extension Firefox Formula 1 free FreeBSD Gmail Google HDD Hsin-chu IE Intel Javascript Lenovo Longhorn Microsoft MSN MySQL Office PCHome performance PHP phpBB pirate Postfix restaurant RSS sendmail software SpamAssassin Subversion SVN Taiwan theme translation Windows WordPress Yahoo

Ads

↑

© Joe Horn 的啟示錄 2021
Powered by WordPress • Themify WordPress Themes