在生产服务器上按预期运行时,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?

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 .