2015-10-14 49 views
0

我將curl shell命令轉換爲PHP curl會話。 我有-o NUL和-w「@ curl-format.txt」。 對於我使用curl_setopt($ ch,CURLOPT_FILE,NULL) 但是,我找不到-UR選項的CURLOPT。 我在PHP curl中的-w選項?

 $cmd = "curl -w \"@curl-format.txt\" -o NUL -s \"".$url."\""; 

     $output = shell_exec($cmd); 

我需要把這些轉化爲PHP捲曲會話。 我這樣做:

  $ch = curl_init($url); 

      $formatfile=fopen(curl-format.txt,"r"); 

      curl_setopt($ch,CURLOPT_FILE,NULL); 

      curl_setopt($ch,CURLOPT_RETURNTRANSFER ,TRUE); 

      curl_exec($ch); 

      curl_close($ch); 

我應該爲-w做些什麼?

+0

你在尋找一個特定的一塊是-w回報信息? – 2015-10-14 19:51:02

+0

你的代碼在哪裏? –

+0

curl_getinfo($ ch)其中$ ch是你的curl實例將返回一個與-w選項相同的信息,不確定它是否具有你所需要的全部信息。 – user3593520

回答

0

在您的curl_exec($ch)之後,您可以使用curl_getinfo($ch, CURLINFO_*);來返回CURLINFO_*常數的值。

http://php.net/manual/en/function.curl-getinfo.php

This may be one of the following constants: 

CURLINFO_EFFECTIVE_URL - Last effective URL 
CURLINFO_HTTP_CODE - Last received HTTP code 
CURLINFO_FILETIME - Remote time of the retrieved document, if -1 is returned the time of the document is unknown 
CURLINFO_TOTAL_TIME - Total transaction time in seconds for last transfer 
CURLINFO_NAMELOOKUP_TIME - Time in seconds until name resolving was complete 
CURLINFO_CONNECT_TIME - Time in seconds it took to establish the connection 
CURLINFO_PRETRANSFER_TIME - Time in seconds from start until just before file transfer begins 
CURLINFO_STARTTRANSFER_TIME - Time in seconds until the first byte is about to be transferred 
CURLINFO_REDIRECT_COUNT - Number of redirects, with the CURLOPT_FOLLOWLOCATION option enabled 
CURLINFO_REDIRECT_TIME - Time in seconds of all redirection steps before final transaction was started, with the CURLOPT_FOLLOWLOCATION option enabled 
CURLINFO_REDIRECT_URL - With the CURLOPT_FOLLOWLOCATION option disabled: redirect URL found in the last transaction, that should be requested manually next. With the CURLOPT_FOLLOWLOCATION option enabled: this is empty. The redirect URL in this case is available in CURLINFO_EFFECTIVE_URL 
CURLINFO_PRIMARY_IP - IP address of the most recent connection 
CURLINFO_PRIMARY_PORT - Destination port of the most recent connection 
CURLINFO_LOCAL_IP - Local (source) IP address of the most recent connection 
CURLINFO_LOCAL_PORT - Local (source) port of the most recent connection 
CURLINFO_SIZE_UPLOAD - Total number of bytes uploaded 
CURLINFO_SIZE_DOWNLOAD - Total number of bytes downloaded 
CURLINFO_SPEED_DOWNLOAD - Average download speed 
CURLINFO_SPEED_UPLOAD - Average upload speed 
CURLINFO_HEADER_SIZE - Total size of all headers received 
CURLINFO_HEADER_OUT - The request string sent. For this to work, add the CURLINFO_HEADER_OUT option to the handle by calling curl_setopt() 
CURLINFO_REQUEST_SIZE - Total size of issued requests, currently only for HTTP requests 
CURLINFO_SSL_VERIFYRESULT - Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER 
CURLINFO_CONTENT_LENGTH_DOWNLOAD - content-length of download, read from Content-Length: field 
CURLINFO_CONTENT_LENGTH_UPLOAD - Specified size of upload 
CURLINFO_CONTENT_TYPE - Content-Type: of the requested document, NULL indicates server did not send valid Content-Type: header 
CURLINFO_PRIVATE - Private data associated with this cURL handle, previously set with the CURLOPT_PRIVATE option of curl_setopt()