未捕获的错误:找不到类 'WindowsAzure\Common\ServicesBuilder' - MS Azure | PHP

Posted

技术标签:

【中文标题】未捕获的错误:找不到类 \'WindowsAzure\\Common\\ServicesBuilder\' - MS Azure | PHP【英文标题】:Uncaught Error: Class 'WindowsAzure\Common\ServicesBuilder' not found- MS Azure | PHP未捕获的错误:找不到类 'WindowsAzure\Common\ServicesBuilder' - MS Azure | PHP 【发布时间】:2019-02-07 02:26:56 【问题描述】:

我在我的 index.php 文件所在的根文件夹中创建了 composer.json 文件,其中包含以下代码:


 "require": 
    "microsoft/windowsazure": "^0.5"
 

在下载 composer.phar 时,我已使用以下方式安装它:

php composer.phar install

我正在尝试在 php.ini 中创建一个表并向其添加实体。我使用命令

use WindowsAzure\Common\ServicesBuilder;
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=******;AccountKey=***/***************************/******************/**********************************==';
$tableRestProxy = ServicesBuilder::getInstance()->createTableService($connectionString);
try 
  // Create table.
  $tableRestProxy->createTable("mytable");

catch(ServiceException $e)
  $code = $e->getCode();
  $error_message = $e->getMessage();
  echo $code.": ".$error_message."<br />";

当我在 Ubuntu 上的本地主机上运行它时,我收到一条错误消息 -

Uncaught Error: Class 'WindowsAzure\Common\ServicesBuilder' not found in /home/my_folder/php-docs-hello-world-master/index.php:30

如果我添加

require_once 'vendor/autoload.php';

在定义我的 $connectionString 之前,我的错误变为:

/index.php - Uncaught RuntimeException: Error creating resource: [message] fopen(https://eyesav.table.core.windows.net/Tables): failed to open stream: Unable to find the socket transport &quot;http&quot; - did you forget to enable it when you configured PHP?

谁能帮我解决这个问题,如果是我的作曲家的安装,或者我的连接字符串,或者其他什么?

提前致谢:)

【问题讨论】:

【参考方案1】:

谁能帮我解决这个问题,如果是我的作曲家的安装,或者我的连接字符串,或者其他什么?

如果我使用你提到的代码,我也可以重现你提到的问题。

请尝试使用以下代码创建表格客户端。它对我有用。

 use MicrosoftAzure\Storage\Table\TableRestProxy;
 use MicrosoftAzure\Storage\Common\ServiceException;
 $tableClient = TableRestProxy::createTableService($connectionString);

以下是来自 azure official document 的演示代码。

<?php 
require_once "vendor/autoload.php";
use MicrosoftAzure\Storage\Table\TableRestProxy;
use MicrosoftAzure\Storage\Common\ServiceException;
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=xxxx;AccountKey=xxxxxxx;';
$tableClient = TableRestProxy::createTableService($connectionString);
try 
    $tableClient->createTable("mytable");

catch(ServiceException $e)
  $code = $e->getCode();
  $error_message = $e->getMessage();
  echo $code.": ".$error_message."<br />";

【讨论】:

我尝试使用上述方法,但出现错误提示:Error creating resource: [message] fopen(https://eyesav.table.core.windows.net/Tables): failed to open stream: Unable to find the socket transport &amp;quot;http&amp;quot; - did you forget to enable it when you configured PHP? 表示需要开启 https 。您可以使用连接字符串 DefaultEndpointsProtocol=http 进行测试。到 https 的中间位置。 我用 http:// 尝试了连接字符串,但它给出了同样的错误。如何启用 http? 请尝试连接字符串$connectionString = 'DefaultEndpointsProtocol=http;AccountName=xxxx;AccountKey=xxxxxxx;'; 关于如何启用https请参考SO thread

以上是关于未捕获的错误:找不到类 'WindowsAzure\Common\ServicesBuilder' - MS Azure | PHP的主要内容,如果未能解决你的问题,请参考以下文章

致命错误:未捕获的错误:找不到类“App\Config”

500 错误“未捕获的错误:找不到类 '\XF\App'”

为啥致命错误:未捕获的错误:找不到类“Illuminate\Foundation\Application”

为啥我收到 PHP 致命错误:未捕获的错误:找不到类“MyClass”? [复制]

PHP致命错误:未捕获错误:找不到类

未捕获的错误:找不到类“SimpleXMLElement”