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

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/

2012-07-16

2012-05-09

CODE - 用 java 發 get 的 http request

...
String getUrl = "http://xx.xx/test.php?sn=xx&path=xx";
URL url = new URL(getUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
loggerHelper.log("Contents of get request");
// 取得 return 值
String lines;
while ((lines = reader.readLine()) != null){
    loggerHelper.log("lines: "+lines);
}
reader.close();
connection.disconnect();
...

cf :
http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/
http://www.exampledepot.com/egs/java.net/post.html