Google Big Query未捕获的异常'Google \ Cloud \ Core \ Exception \ ServiceException

时间:2017-07-27 09:49:06

标签: php google-bigquery

我正在尝试实施Google Big Query。我不得不使用composer来安装谷歌库,因为它不适用于存储客户端和大查询客户端。 我的代码从云存储读取文件并将数据插入Big查询表。 我收到了以下错误和警告

  

PHP致命错误:未捕获的异常   'Google \ Cloud \ Core \ Exception \ ServiceException',带有消息'选项   这种卷曲实现不支持20056。在   /base/data/home/apps/s~xxx/1.402961109127965627/vendor/google/cloud/src/Core/RequestWrapper.php:241   堆栈跟踪:

     

0 /base/data/home/apps/s~xxx/1.402961109127965627/vendor/google/cloud/src/Core/RequestWrapper.php(150):   谷歌\云\核心\ RequestWrapper-> convertToGoogleException(对象(谷歌\应用服务引擎\运行时\ CurlLiteOptionNotSupportedException))

     

1 /base/data/home/apps/s~xxx/1.402961109127965627/vendor/google/cloud/src/Core/RestTrait.php(96):   谷歌\云\核心\ RequestWrapper->发(对象(GuzzleHttp \ PSR7 \请求),   阵列)

     

2 /base/data/home/apps/s~xxx/1.402961109127965627/vendor/google/cloud/src/BigQuery/Connection/Rest.php(220):   Google \ Cloud \ BigQuery \ Connection \ Rest-> send('jobs','insert',Array)

     

3 /base/data/home/apps/s~xxx/1.402961109127965627/vendor/google/cloud/src/BigQuery/Table.php(344):   Google \ Cloud in   /base/data/home/apps/s~xxx/1.402961109127965627/vendor/google/cloud/src/Core/RequestWrapper.php   在第241行

     

PHP警告:出于安全原因,已禁用php_sapi_name()。   它可以通过添加到它来重新启用   google_app_engine.enable_functions ini变量在您的应用程序中   php.ini in   /base/data/home/apps/s~datascrub-152522/1.402961109127965627/vendor/guzzlehttp/guzzle/src/Client.php   在第173行

<?php
session_start();

# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';

# Imports the Google Cloud client library
use Google\Cloud\BigQuery\BigQueryClient;

use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Core\ExponentialBackoff;

$projectId="xxx-1111";
$datasetId="datasetid";
$tableId="test";
$bucketName="gs://my-bucket";

$objectName="Cloud_SQL_Export.csv";
echo "\n".$projectId."==".$datasetId."==".$tableId."==".$bucketName."==".$objectName."\n";

import_from_storage($projectId, $datasetId, $tableId, $bucketName, $objectName);


function import_from_storage($projectId, $datasetId, $tableId, $bucketName, $objectName)
{

    echo "inside function";

    // determine the import options from the object name
    $options = [];
    /*if ('.backup_info' === substr($objectName, -12)) {
        $options['jobConfig'] = ['sourceFormat' => 'DATASTORE_BACKUP'];
    } elseif ('.json' === substr($objectName, -5)) {
        $options['jobConfig'] = ['sourceFormat' => 'NEWLINE_DELIMITED_JSON'];
    }*/
    $options['jobConfig'] = [ 'sourceFormat' => 'CSV', 'skipLeadingRows' => 1 ];
    print_r($options);
    echo "gfgfhg".$projectId;
    // instantiate the bigquery table service
    $bigQuery = new BigQueryClient([
            'projectId' => $projectId,
    ]);


    $dataset = $bigQuery->dataset($datasetId);


    $table = $dataset->table($tableId);
    // load the storage object
    $storage = new StorageClient([
            'projectId' => $projectId,
    ]);

    $object = $storage->bucket($bucketName)->object($objectName);


    // create the import job
    $job = $table->loadFromStorage($object, $options);
    echo "job set";
    // poll the job until it is complete
    $backoff = new ExponentialBackoff(10);
    $backoff->execute(function () use ($job) {
        echo 'Waiting for job to complete' . PHP_EOL;
        $job->reload();
        if (!$job->isComplete()) {
            throw new Exception('Job has not yet completed', 500);
        }
    });
        // check if the job has errors
        if (isset($job->info()['status']['errorResult'])) {
            $error = $job->info()['status']['errorResult']['message'];
            echo 'Error running job: ' . PHP_EOL." ". $error;
        } else {
            echo 'Data imported successfully' . PHP_EOL;
        }
}

1 个答案:

答案 0 :(得分:1)

通过在php.ini文件中添加extension =“php_curl.dll”来解决问题