2017-05-05 128 views
-1

我創建了一個非常簡單的小型php腳本,我希望能夠在我的MacOSX終端上的命令行中運行。php文件未在命令行中運行......但在本地主機上運行時工作

如果我只輸入echo "test"即可得到輸出。

現在我向該腳本添加了一個curl請求,以從API獲取一些數據,然後鍵入print_r $result

不幸的是,結果永遠不會輸出到命令行中。如果我現在在我的MAMP本地主機上運行完全相同的php文件,一切工作正常,內容輸出正確。

這是我的代碼:

require 'connection.php'; 

$store = new connection('danny', 'https://store-bgf5e.mybigcommerce.com/api/v2/', 'XXXXX'); 
$customers = $store->get('/customers'); 

foreach($customers AS $customer) { 
    print "------ Getting Adresses for: " . $customer['first_name'] . ' '   . $customer['last_name'] . ' -------'; 
    if(isset($customer['addresses']['resource'])) { 
     print_r($store->get($customer['addresses']['resource'])); 
    } 
} 

exit; 

我知道,API返回的地址就好了這樣的電話肯定能行。

這是捲曲的話說:

* Trying 63.141.159.120... 
* TCP_NODELAY set 
* Connected to store-bgf5e.mybigcommerce.com (63.141.159.120) port 443 (#0) 
* ALPN, offering http/1.1 
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH 
* successfully set certificate verify locations: 
* CAfile: /Applications/MAMP/Library/OpenSSL/cert.pem CApath: none 
* SSL connection using TLSv1.2/ECDHE-RSA-AES128-GCM-SHA256 
* ALPN, server accepted to use http/1.1 
* Server certificate: 
* subject: C=AU; ST=New South Wales; L=Ultimo; O=Bigcommerce Pty Ltd; CN=*.mybigcommerce.com 
* start date: Jun 4 00:00:00 2015 GMT 
* expire date: Sep 1 12:00:00 2018 GMT 
* subjectAltName: host "store-bgf5e.mybigcommerce.com" matched cert's "*.mybigcommerce.com" 
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA 
* SSL certificate verify ok. 
> GET /api/v2/customers HTTP/1.1 
Host: store-bgf5e.mybigcommerce.com 
Authorization: Basic  ZGFubnk6M2QyNjE5NTdjZGNjMTNlYmU1MTJiNDRiMjE1NGJiZGZmMGRjNTUxMw== 
Accept: application/json 
Content-Type: application/json 

< HTTP/1.1 200 OK 
< Server: openresty 
< Date: Fri, 05 May 2017 19:26:27 GMT 
< Content-Type: application/json 
< Transfer-Encoding: chunked 
< Connection: keep-alive 
< Set-Cookie: fornax_anonymousId=0ff167a5-e158-4ff8-8962-67b19bd4271b; expires=Mon, 03-May-2027 19:26:27 GMT; path=/; domain=.store-bgf5e.mybigcommerce.com 
< Last-Modified: Thu, 13 Apr 2017 22:34:54 +0000 
< X-BC-ApiLimit-Remaining: 2147483622 
< X-BC-Store-Version: 7.6.0 
< 
* Curl_http_done: called premature == 0 
* Connection #0 to host store-bgf5e.mybigcommerce.com left intact 

對我來說,它看起來像捲曲被正確執行的一切。這幾乎就像成功的curl請求阻止任何其他PHP代碼運行。由於「print_r」,我希望看到地址被打印到命令行。

在此先感謝您提供的任何提示。

+0

您需要發佈腳本。 – Barmar

+0

代碼por。 –

+0

更新了問題,對不起傢伙! – user3307277

回答

0

想通了。我用這個框架連接到的Bigcommerce API:https://github.com/adambilsing/PHP-cURL-lib-for-Bigcommerce-API/blob/master/connection.php

connection類的http_parse_headers方法有一個,如果線54上聲明:

if ($retVal['X-Bc-Apilimit-Remaining'] <= 100) { 
    sleep(300); 
} 

這將觸發腳本去睡覺即使$retVal['X-Bc-Apilimit-Remaining']null

將其更改爲這個固定的問題:

if (isset($retVal['X-Bc-Apilimit-Remaining']) && $retVal['X-Bc-Apilimit-Remaining'] <= 100) { 
    sleep(300); 
} 

,一旦你看看它這是很明顯的。我甚至沒有意識到在PHP中有一個睡眠命令。

感謝所有試圖理解這一點的人:)

0

你可以嘗試var_dump你的結果,看看發生了什麼。對於你的捲曲反應,我沒有看到任何內容長度的標題,我認爲curl返回空字符串。

請問你能發佈你的php代碼嗎?

相關問題