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

2013-04-13

CODE - 執行 php 出現的 Host key verification failed. 255 / Host key verification failed

php code
$cmd = '/usr/bin/ssh root@x.x.x.x cat /home/logs/consumer.log 2>&1';
$last_line = system($cmd, $retval);
echo json_encode($retval).' / '.$last_line;

會顯示
Host key verification failed. 255 / Host key verification failed.
(或用 exec , retval 是 255 的情況)

解決方法 :
由執行 php code 的機器(這裡是 stage), 用 wwwrun 的身份去 ssh 該主機, 按 yes 即可
大概是因為 vm clone 好後, 雖 stage 的 public key 已加在該主機的 authorized_keys2 裡,
但實際上卻未曾連過, 只要連過 public key 便可在 authorized_keys2 裡生效

2012-10-13

CODE - php 字串取代

example :
$path = '/home/nas/webhd_14/e2/c3/10107664/50012/sync/a3/string';
$path = preg_replace('/home\/nas/', 'net', $path);
# output: /net/webhd_14/e2/c3/10107664/50012/sync/a3/string
$str = 'hello.@.@world';
$key = preg_replace(array('/\./', '/\@/'), '_', $str);
# output: hello||||world

2012-08-18

CODE - php 檢查字串的編碼

本來是要用來檢查 mediainfo parsing 後的字串, 以便轉成 xml 時不會有誤
雖然後來沒這麼做, 但還是把這段檢查紀錄一下

2012-07-23

CODE - php xml to array

code as below
//$xml = implode('', $output);
$xmlObj = simplexml_load_string($xml);
$json = json_encode($xmlObj);
$arr = json_decode($json, true);
print_r($arr);

cf : http://jaspreetchahal.org/php-xml-to-array-simplest-way/