Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Arrays
- Session
- Linux
- 무료다운로드쿠폰
- MySQL
- HTML
- composer-php
- JSON
- Ajax
- Regex
- jquery
- UTF-8
- 경영
- string
- file-upload
- post
- Apache
- Forms
- Laravel
- 웹하드추천
- JavaScript
- date
- variables
- OOP
- 전략
- function
- 웹하드순위
- curl
- php
Archives
- Today
- Total
개발! 딱 깔끔하고 센스있게!
Guzle HTTP PHP 클라이언트 연결 제한 시간 사용하기 본문
나는 구즈le으로 url-s 목록을 열어 제목을 얻었다.
몇몇 url 응답 시간이 너무 길어서 열 수 없어, 나는 그것들을 무시하고 싶다.
Guzle이 이상을 던지기 전에 나는 최대 20초 이상 시간을 바꾸고, 연결 시간을 2초로 제한하고 싶다.
나는 이 코드가 있는데, 그것은 여전히 더 오랜 시간이 필요하다.
format("d.m.Y H:i:s"); echo $start."\n"; $client = new Guzzle\Http\Client(); Guzzle\Http\StaticClient::mount(); try { $request = $client->get('http://takestoolongexample', [], ['connect_timeout' => 2, 'timeout' => 3, 'debug' => true]); $response = $request->send(); var_dump($response->getStatusCode()); } catch (Exception $e) { echo "\n".$e->getMessage()."\n"; } $end = new \DateTime("now"); $end = $end->format("d.m.Y H:i:s"); echo "\n".$end."\n"; ?>
다음은 예례 결과다.
네가 본 것처럼 13초 걸렸다.
$ php test.php 30.12.2013 22:00:07 * getaddrinfo(3) failed for takestoolongexample:80 * Couldn't resolve host 'takestoolongexample' * Closing connection 0 [curl] 6: Couldn't resolve host 'http://takestoolongexample' http://takestoolongexample 30.12.2013 22:00:20
(http://takestoolongexample 진정한 url, 여기서 변경)
대답
guzle 버전 (Guzzle 4) 의 최신 해결 방안이다.
$request = $client->get(sprintf("%s/noisesize.api", $this->noiseConfig->url), [ 'timeout' => 5, // Response timeout 'connect_timeout' => 5, // Connection timeout ]);
Guzle Htp Excception Requestexception
최신 버전의 문서는 여기에 있습니다: 구즈클 요청 옵션 – 연결이 초과되었습니다.
'개발 스크랩 메모 > PHP' 카테고리의 다른 글
PHP FreeTDS 확장을 사용하여 MSSQL 서버에서 UTF-8 문자 세트로 데이터 가져 오기 (0) | 2020.12.18 |
---|---|
PHP 기본 도메인 / URL을 얻는 방법? (0) | 2020.12.18 |
PHP 변수, 메소드, 클래스 등의 유효한 문자는 무엇입니까? (0) | 2020.12.17 |
변수를 php 에서 bash 로 전달합니다 (0) | 2020.12.17 |
PHP 의 마이크로프레임 (병이나 Sinatra) [닫기] (0) | 2020.12.17 |