顯示具有 PHP 標籤的文章。 顯示所有文章
顯示具有 PHP 標籤的文章。 顯示所有文章

2008-06-11

寫程式掃HDD檔案的一點小技巧

最近要處理一個程式,簡單來說就是要去新的 RAID 裡把檔案一個個翻出來跟舊的 RAID 比對看檔案大小跟日期修改等資訊(轉檔出問題要重轉)

原本還想說用 PHP opendir 去開一個 resource 來一層層掃,後來經高人(我們家老大)指點突然想通了

unix find 指令是個好幫手

因為我要掃整個 RAID,而且這是個好幾十G的資料量,一層層掃是跟自己過不去,於是我先做了下列的事;

  • 切換到要掃的資料夾那層
  • 下指令 #find . > ~/file_list.idx
簡單來說就是用 find 把從要掃的那層資料夾開始,整個檔案樹狀結構都先 output 出來成為一個 file list,這樣 PHP 只要直接去 fopen 那個 file list,然後透過變數串接加上像是 filesize() / filemtime() 等 PHP function 就可以輕鬆得到所需的效果,省時又方便(程式又簡單)

所以要靈活運用 UNIX 指令來幹噁心的事呀 XDDDD

2008-05-27

mantis 在 file upload 部份的設定

mantis 這套 bug tracking 應該蠻多人在用,就不多做介紹了

這個設定主要是針對上傳檔案容量大小控制的部份說說明,


總共有三個地方要改(my.cnf是特殊狀況)

  1. mantis 自身設定檔
    • 有兩個, 一個叫 config_defaults_inc.php, 這是所有的基本設定, 另一個叫config_inc.php, 這個可以 ovrride 掉前一個, 所以我們改這個就好
    • $g_allow_file_upload = ON;
      $g_max_file_size = 20000000; #20M, 不過我 php.ini 有鎖要搭配著看)
    • 另外由於預設 $g_file_upload_method = DATABASE; 所以檔案都會塞進DB 裡mantis.mantis_bug_file_table, 當然也可以設定為 DISK 磁碟機上(或一台 ftp server)
  2. php.ini
    • 不用多說, 看底下
    • max_execution_time = 300
      upload_max_filesize = 12M
      post_max_size= 12M
      memory_limit= 128M
  3. my.cnf
    • 因為我們是設定寫 DB, 才會需要動到 my.cnf
    • max_allowed_packet = 32M #就是它了
以上設定要相互搭配, 才能拉大 upload file 的 size, 至於把檔案放 DB 蠢不蠢這件事就不討論, mantis 本身有提供 utility 可以把檔案或專案轉出來到 DISK 上

http://yourmantishost/admin/system_utils.php

其他更詳細的請自己參考文件吧

PHP 在 32bit & 64bit 平台的差異

這個問題是在做一個系統轉換機器時發現的(從 i386 -> amd64)

主要是 Integer 在 32bit & 64bit 環境下位數表現的問題,我是在 dechex() 這個 function 踩到地雷 跟,不過其實應該只會在超過 65536 的整數才會出事(32bit unsigned),以下是 PHP 官方站相關參考

http://tw2.php.net/manual/en/function.dechex.php

To force the correct usage of 32-bit unsigned integer in some functions, just add '+0' just before processing them.

for example
echo(dechex("2724838310"));
will print '7FFFFFFF'
but it should print 'A269BBA6'

When adding '+0' php will handle the 32bit unsigned integer
correctly
echo(dechex("2724838310"+0));
will print 'A269BBA6'