2017-05-05 127 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代码吗?

相关问题