Information
2015.12.02 10:40
[스크랩] PHP 쓰레드 흉내내기
조회 수 90967 추천 수 0 댓글 0
http://w-shadow.com/blog/2008/05/24/improved-thread-simulation-class-for-php/ : 원본 참조링크
글자가 깨지므로 코드 첨부 :
바로 코드 테스트 들어감
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | include_once ( "thread.class.php" ); //쓰레드 구동 함수 function test( $s , $s1 , $sleep_time ){ sleep( $sleep_time ); return sprintf( "%s-->%s : sleep time : %s" , $s , $s1 , $sleep_time ); } $program_start_time = microtime(true); //쓰레드 생성 $thread1 = new Thread( "localhost" ); //쓰레드로 돌릴 함수를 등록 그리고 매개변수를 전달 한다. - 매개변수의 개수와 맞아야함 $thread1 ->setFunc( 'test' , array ( "testString" , "testString1" ,2)); $thread1 ->start(); $thread2 = new Thread( "localhost" ); $thread2 ->setFunc( 'test' , array ( "testString" , "testString1" ,2)); $thread2 ->start(); // 종료된 쓰레드의 응답을 기다림 while ( ! $thread1 ->finished || ! $thread2 ->finished){ $thread1 ->query(); $thread2 ->query(); } //결과 printf( "Thread1: %s <br>" , $thread1 ->result); printf( "Thread2: %s <br>" , $thread1 ->result); printf( "Total execution time : %s seconds<br>" , (microtime(true)- $program_start_time ) ); /* 동일 하게 2초를 사용 했고 전체 사용 시간이 2초 인것을 알수 있다. ㅎ_ㅎ Thread1 : testString-->testString1 : sleep time : 2 Thread2 : testString-->testString1 : sleep time : 2 Total execution time : 2.0561389923096 seconds */ |
글자가 깨지므로 코드 첨부 :
기본적인 원리는 이렇다 스레드 객체를 생성 할때에 호스트 이름만 적어주면
현재 파일을 찾고 지정한 함수 이름을 호출을 하는데 매개변수 까지 전달 해서 호출 결과를 받아 올수 있다.
쓰레드 클래스 에서는 HTTP 로 동시에 전체 호출 하고 결과는 차근 차근 받아온다.
훔... 유용할듯 ..................................... ㅋ
역시 외쿡 사람들이 잘하는 사람들이 많음 우찌 이런 사랑스러운 코드를..............................
URL: http://code.p-ark.co.kr/154
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
» | Information | [스크랩] PHP 쓰레드 흉내내기 | LionHeart | 2015.12.02 | 90967 |
18 | Information | 관련기사 및 블로그 포스팅 등등 | LionHeart | 2015.11.24 | 69146 |
17 | Information | 도메인 가격비교 | LionHeart | 2015.11.11 | 60571 |
16 | Information | 동영상 자막, 뱁션 | LionHeart | 2015.11.07 | 92883 |
15 | Information | 아르바이트생이 갑자기 그만둔 경우 근로계약 위반에 해당하나요? | LionHeart | 2014.12.30 | 87434 |
14 | Information | 대법원 2005. 6. 10. 선고 2004다29934 판결 | LionHeart | 2014.11.28 | 67146 |
13 | Information | [동아일보] 죽음도 지울수 없는 ‘주홍글씨’… 지워야 산다 | LionHeart | 2014.11.14 | 88239 |
12 | Information | MONSTA web FTP | LionHeart | 2014.10.01 | 134864 |
11 | Information | 404 NOT FOUND | LionHeart | 2014.09.30 | 70500 |
10 | Information | XE 속도개선 (XE 캐시파일 초기화 시간 줄이는 팁) - 다국어 제거 | LionHeart | 2014.08.22 | 70565 |
9 | Information | XE 속도 개선팁 모음 1 | LionHeart | 2014.08.21 | 93777 |
8 | Information | 나눔글꼴 웹폰트 | LionHeart | 2014.05.04 | 110467 |
7 | Information | Virus Chaser 8.0 & Remover | LionHeart | 2013.11.03 | 98354 |
6 | Information | mysql 5.5.9 언어 설정 latin1 -> euckr 변경 | LionHeart | 2013.10.31 | 98133 |
5 | Information | ns2 version 2.35 install | LionHeart | 2013.10.26 | 90862 |
4 | Information | 우분투에 ns 2.35 설치 | LionHeart | 2013.10.24 | 91089 |
3 | Information | Zend Guard 3.3.0 x64 | LionHeart | 2013.10.24 | 96003 |
2 | Information | network simulator 3 (ns-3) overview | LionHeart | 2013.10.24 | 185521 |
1 | Information | jwplayer 6.6 embed source code | LionHeart | 2013.10.18 | 80718 |