dongpangfu6322 2019-05-30 04:44
浏览 40

在生产服务器上按预期运行时,Php数据存储区脚本在开发服务器上失败

Have a look on the following datastore script:

<?php
use google\appengine\datastore\v4\Mutation\Operation;
use google\appengine\datastore\v4\BeginTransactionRequest;
use google\appengine\datastore\v4\BeginTransactionResponse;
use google\appengine\datastore\v4\CommitRequest;
use google\appengine\datastore\v4\CommitRequest\Mode;
use google\appengine\datastore\v4\CommitResponse;
use google\appengine\datastore\v4\RollbackRequest;
use google\appengine\datastore\v4\RollbackResponse;
use google\appengineuntime\ApiProxy;
use google\appengineuntime\ApplicationError;


function beginTransaction(){
    global $request, $response;
    $request = new BeginTransactionRequest();
    $request->setCrossGroup(true);
    $response = new BeginTransactionResponse();
    try{
        ApiProxy::makeSyncCall('datastore_v4', 'BeginTransaction', $request, $response, 60);
    }
    catch(ApplicationError $e){
        echo $e->getMessage();
        exit();
    }

    $request = new CommitRequest();
    $request->setTransaction($response->transaction);
    $request->setMode(Mode::TRANSACTIONAL);
}

function prepareEntity($entity, $name, $author, $channel){
    global $projectId;
    $entity->mutableKey()->mutablePartitionId()->setDatasetId($projectId);
    $entity->mutableKey()->addPathElement()->setKind('Books');
    $entity->addProperty()->setName('Name')->mutableValue()->setStringValue($name);
    $entity->addProperty()->setName('Author')->mutableValue()->setStringValue($author);
    $entity->addProperty()->setName('Channel')->mutableValue()->setStringValue($channel);
}

function commit(){ 
    global $request, $response;
    $response = new CommitResponse();     
    try{
        ApiProxy::makeSyncCall('datastore_v4', 'Commit', $request, $response, 60);
    }
    catch(ApplicationError $e){
        echo $e->getMessage();
        exit();
    }
}


$projectId = $_SERVER['APPLICATION_ID'];
beginTransaction();

prepareEntity(
    $request->addMutation()->setOp(Operation::INSERT)->mutableEntity(),
    'Contemporary Abstract Algebra',
    'J Gallian',
    'Mutation'
    );

prepareEntity(
    $request->addMutation()->setOp(Operation::INSERT)->mutableEntity(),
    'Principals of Mathematical Analysis',
    'Rudin',
    'Mutation'
    );
commit('Mutation Commit');
echo "<h2>Mutation Commit</h2>";
foreach($response->getMutationResultList() as $mutationResult){
    echo 'Book@'. end($mutationResult->getKey()->getPathElementList())->getId(). '<br/>';
}
echo '<hr/>';

beginTransaction();
prepareEntity(
    $request->mutableDeprecatedMutation()->addInsertAutOId(),
    'Contemporary Abstract Algebra',
    'J Gallian',
    'Deprecated Mutation'
    );

prepareEntity(
    $request->mutableDeprecatedMutation()->addInsertAutOId(),
    'Principals of Mathematical Analysis',
    'Rudin',
    'Deprecated Mutation'
    );

commit();
echo "<h2>Deprecated Mutation Commit</h2>";
foreach($response->getDeprecatedMutationResult()->getInsertAutoIdKeyList() as $key){
    echo 'Book@'. end($key->getPathElementList())->getId(). '<br/>';
}
echo '<hr/>';

In this script the commits using mutation don't work on the development server. Neither they save the data nor they throw any error. Though they work as expected on the production server. The deprecated mutations work as expected on both development server and production server. I debugged and found that make_call function call in use google\appengineuntime\RealApiProxy is unable to produce a response. Can someone please explain this behavior. Is that a bug in the development runtime?

  • 写回答

1条回答 默认 最新

  • dongyue110702 2019-05-31 00:51
    关注

    I expect your problem is with the use google\appengine\datastore\v4\... lines, you should probably use the google-cloud-datastore libraries. The getting started guide is at https://cloud.google.com/php/getting-started/using-cloud-datastore .

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?