2005년 7월 27일 수요일

PHP 를 이용한 SCP,SFTP

A PHP condition & Sample when Using sFtp/scp in PHP script Writtened by Jinsuk,yoon
feedback : udanax@joyon.com


it able to open a SSH connection to use SFTP / SCP without any problems
You need first Extension libssh2, PECL libraries

reference
http://docs.php.net/en/ref.ssh2.html
http://pecl.php.net
http://sourceforge.net/projects/libssh2/)


sftp와 scp를 사용하기위한 PHP환경과 예제입니다.
먼저 sftp와 scp를 사용하기 위해서는 SSH Connection이 가능해야하기때문에, libssh2, PECL라이브러리를 확장하세요. (system()명령으로도 가능은 하지만, 여러가지 고려함에..)

아래의 샘플을 통하여, php스크립트를 통해 원격으로 서버대서버로 sftp프로토콜을 사용하여 파일전송을 할수있습니다.



Example


define('SFTP_ADDR', '211.233.83.189');

$start_time = microtime(true);



// establish connection to FTP over SSH
$connection = ssh2_connect(SFTP_ADDR, 22);
$sftp = ssh2_sftp($connection);


$src_file = '/usr/local/www/data.src';
$dst_sftp_file = 'ssh2.sftp://' . $sftp . '/www/data.dst';
$dst_scp_file = '/www/data.dst';


//use SFTP wrapper
copy($src_file, $dst_sftp_file);


//use SCP
ssh2_scp_send($connection, $src_file, $dst_scp_file);

print 'Total Time: ' . microtime(true) - $start_time;




Expected result:
----------------
Expected: FAST file transfer, over 3MB/sec

Actual result:
--------------
Result: SLOW file transfer, around 30KB/sec

Feedback : udanax@joyon.com

2005년 7월 22일 금요일

CVS 커밋 발생시점에 소스 export 하기

지금 개발 하고 있는 환경이 주로 PHP를 이용한 개발 이라 CVS에서 소스를 가져와서 수정하고 SFTP로 테스트 서버에 전송 확인한 후에
CVS에 커밋을 하는 작업이 발생한다.

이제껏 자바 개발의 경우 소스를 CVS에 커밋 한다고 해도 매번 컴파일작업이 발생하기 때문에 개발 효율은 그리 높지 않았다.
PHP의 생산성은 자바와는 비교가 되지 않을 정도 이지만 위에서 언급한 CVS커밋 작업과 서버에전송작업이 업무 효율을 떨어뜨리는 원인이 되고 있었다.

PHP의 경우 commit한 것을 wep page를 통해 확인 하기 때문에 CVS 와 아파치 DocumentRoot를 연결해 두면 작업한 소스를 CVS 에 커밋 하는 것만으로 확인이 가능해 진다.

이하는 이를 위한 설정 이다.

CVSROOT위치 /home/cvs/
모듈명 bin
아파치 DocumentRoot /home/apache/doc

bin모듈에 소스를 커밋 하면 /home/apache/doc/bin 에 변경한 것이 반영되도록 한다.

[root@xxxx root]# cd /home/cvs
[root@xxxx cvs]# ls
bin CVSROOT cvstest test

만들어 주어야 하는 파일
auto_update.pl
binUpdate.sh

[root@xxxx CVSROOT]# view auto_update.pl
#!/usr/bin/perl
#cvs path
$cvs = '/usr/bin/cvs';
$usage = "usage: auto_update.pl WORKDIR [MODE]";
# process arguments
die $usage, "
" unless $workdir = $ARGV[0];
$chmod = $ARGV[1] ? "; chmod -R $ARGV[1]" : "";
# main update process which must be executed in background.
$cmd = "(cd $workdir; $cvs -q update $chmod) &";
system($cmd);
# last message.
$date = `date`; chomp($date);
$mesg = "$workdir automatically updated at $date";
print "$mesg
";

[root@xxxx CVSROOT]# view binUpdate.sh
#!/bin/sh
/home/cvs/CVSROOT/auto_update.pl /home/apache/doc


수정해 주어야 하는 파일
loginfo에 이하의 내용을 추가해 주면 된다.

bin /home/cvs/CVSROOT/binUpdate.sh bin


[root@xxxx CVSROOT]# view loginfo
# The "loginfo" file controls where "cvs commit" log information
# is sent. The first entry on a line is a regular expression which must match
# the directory that the change is being made to, relative to the
# $CVSROOT. If a match is found, then the remainder of the line is a filter
# program that should expect log information on its standard input.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name ALL appears as a regular expression it is always used
# in addition to the first matching regex or DEFAULT.
#
# You may specify a format string as part of the
# filter. The string is composed of a `%' followed
# by a single format character, or followed by a set of format
# characters surrounded by `{' and `}' as separators. The format
# characters are:
#
# s = file name
# V = old version number (pre-checkin)
# v = new version number (post-checkin)
# t = tag or branch name
#
# For example:
#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog
# or
#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog

bin /home/cvs/CVSROOT/binUpdate.sh bin


---------주의 사항---------
퍼미션 관련 에러에 조심하기만 하면 아무 문제 없이
커밋한 소스를 아파치DocumentRoot 에 밀어주게 된다.

아파치 DocumentRoot의 유저 가 xxx라면
cvs의 그룹에 xxx를 등록해 주면 된다.

[root@xxx CVSROOT]# vi /etc/group
xxx:x:502:cvs사용유저1 ,cvs사용유저1,cvs사용유저2
cvs:x:503:cvs사용유저1,cvs사용유저1,cvs사용유저2,xxx


/home/apache/doc/에서
cvs checkout bin을 먼저 실행해 bin을 체크 아웃 해두는 것도 잊지 말아야 한다.
checkout시 bin 에 lock관련 정보를 write할수 없다는 에러가 발생하면 chgrp -R bin해주면 되겠죠...

2005년 7월 20일 수요일

다국적 언어 처리

황정철님 블로그
http://blog.naver.com/hjc1108.do?edirect=Log&logNo=60011201293
네이버 검색결과
http://search.naver.com/search.naver?where=nexearch&query=ASCII+ORACLE+US7ASCII+jdbc+utf-8&hw=1