내 PHP 프로젝트는 컬을 사용하여 WCF REStful 웹 서비스에서 데이터를 가져와 작동합니다.PHP - curl_exec taking 100ms
그러나 어떤 이유 때문에 curl_exec 함수는 WCF 웹 서비스가 동일한 컴퓨터에 있더라도 반환하기 위해 항상 약 100ms가 걸리고 호출되는 WCF 서비스 함수는 실행하는 데 3ms 밖에 걸리지 않습니다.
나는 WCF 서비스를 프로파일 링했고 전체 WCF 스택은 HTTP 요청을 받아들이고 10ms 미만의 결과 XML (5 개의 요소가있는 작은 XML 구조)을 반환합니다.
다음은 내 컬 셋업 코드 : curl_exec하는
$curl = curl_init($this->uri);
curl_setopt($curl, CURLOPT_HEADER , true); // return response HTTP headers in output
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // return result instead of echoing
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop cURL from verifying the peer's certificate. This is set because by default (and right now) cURL does not trust /any/ certificate.
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // follow redirects, Location: headers (but does it really?)
curl_setopt($curl, CURLOPT_MAXREDIRS , 10 ); // but dont redirect more than 10 times
curl_setopt($curl, CURLOPT_CUSTOMREQUEST , $this->method);
if(isset($this->username ))
curl_setopt($curl, CURLOPT_USERPWD , $this->username . ':' . $this->password);
if(isset($this->userAgent))
curl_setopt($curl, CURLOPT_USERAGENT, $this->userAgent);
if(isset($this->content)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->content);
array_push($this->headers, 'Content-Length: '. $this->contentLength);
if(isset($this->contentType))
array_push($this->headers, 'Content-Type: ' . $this->contentType);
}
if(isset($this->contentFile)) {
curl_setopt($curl, CURLOPT_INFILE , $this->contentFile );
curl_setopt($curl, CURLOPT_INFILESIZE, $this->contentLength);
array_push($this->headers, 'Content-Length: '. $this->contentLength);
array_push($this->headers, 'Content-Type: ' . $this->contentType);
}
if(count($this->headers) > 0)
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
통화가 코드 블록 직후 발생, 그리고 내가 지속적으로이 100ms에서 측정한다 curl_exec 전화입니다.
나는이 PHP 사이트의로드 시간을 줄이는 것이 중요하며 왜 이러한 일이 발생하는지 이해할 수 없습니다.
UPDATE :
컬의 curl_exec는 항상 내가 (같은 PHP 페이지 실행에서) 두 번째 curl_exec 요청을 할 때 매우 흥미롭게도 있지만,에 관계없이 요구되는 내용의이 100ms을 보인다는 빨리 많이 완료 - 약 20ms로 .
신비가 깊어집니다.
UPDATE 2
가 I (즉 curl_getinfo 실현)는 타이밍 정보를 포함하는 연관 - 배열을 반환한다.
'total_time' => 0.016,
'namelookup_time' => 0,
'connect_time' => 0,
'pretransfer_time' => 0,
'starttransfer_time' => 0.016,
지연이 namelookup에 보이지만,이 (이상)처럼 모든 후속 요청 반면
'total_time' => 0.125,
'namelookup_time' => 0.125,
'connect_time' => 0.125,
'pretransfer_time' => 0.125,
'starttransfer_time' => 0.125,
: 내가 처음 컬 요청에서 정보를 덤프 때 나는 다음을 참조 나는 왜 DNS 조회가 Windows (서버 OS)가 이미 캐싱 된 DNS 정보를 가지고 있고 다른 응용 프로그램 (데스크톱, ASP.NET 등)이 1ms 미만으로 이름을 확인할 수 있다고 가정하면 cnRL이 그렇게 오래 걸리는 지 모르겠다. 125ms.
cURL의 특별한 점은 OS의 DNS 캐시를 사용할 수 없다는 것입니다.
오버 헤드, 연결, TCP, HTTP 프로토콜 등 서비스가 로컬 인 경우 HTTP 요청을 사용해야하는 이유는 무엇입니까? 더 빠른 방법이 없습니까? 그리고 WCF 서비스의 프로파일 링은 아마 그 모든 불쾌한 연결 및 HTTP 비즈니스가 잠시 동안 계속 된 후에 시작될 것입니다. – Wrikken
witwick의 의견에 Ditto. 타이밍 계산에서 전체 TCP/HTTP 오버 헤드를 무시했습니다. 즉, 완전히 서비스되지 않은 페이지로 바뀌는 타이밍은 어떨까요? WCF 응답 중 하나와 동일한 크기의 단순한 정적 HTML 페이지이며 말풍에 걸리는 시간을 확인하십시오. 100ms라면 wcf가 아니며 더 많은 컬/오버 헤드가 발생합니다. –
같은 시스템에 있다면 다른 시스템의 데이터베이스에서 바로 읽지 않는 이유는 무엇입니까? –