PHP致命错误:未定义的类常量'WRITE_SCOPE'

时间:2015-04-08 16:28:02

标签: php google-app-engine

我在Google appengine中使用PHP应用, 我试图读取输入文件并将其写入存储桶中的输出文件,如下所示。

$input_file = fopen('gs://mybucket/input.csv','r');
$output_file = fopen('gs://mybucket/output.csv', 'w');

尝试写一些像

这样的日期
while(!feof($input_file)) {
    $csv = fgetcsv($input_file,1024);
    if(!$csv[0]){ 
        fclose($output_file); //Close the connection when the loop ends
        fclose($input_file);
        exit(0);
    }
    fwrite($output_file, $csv[0]."\r\n");
}

它工作正常,当我尝试将一些数据上传到输入文件时,它也成功写入output.csv。但如果我尝试超过5或6次,它会开始在下面的appengine日志中抛出一个错误。任何有关解决此问题的帮助都将受到高度赞赏!

 2015-04-08 21:31:29.006 PHP Fatal error:  Undefined class constant 'WRITE_SCOPE' in /base/data/home/runtimes/php/sdk/google/appengine/ext/cloud_storage_streams/CloudStorageWriteClient.php on line 214

更新: 我认为这是因为同时打开2个文件流, 有人解决了这个问题并解决了这个问题!

$input_file = fopen('gs://mybucket/input.csv','r');
$array_acc = array();
while(!feof($input_file)) {
    $csv = fgetcsv($input_file, 1024);
    if($csv[0]) array_push($array_acc, $csv[0]);
}
fclose($input_file);   //close the file

$acc_count = count($array_acc);
$output_file  = fopen('gs://tool-synclio/output.csv','w'); // Open the output file now
while($acc_count > 0){
    fwrite($output_file,$array_acc[$acc_count]."\r\n");
    $acc_count --;
}
fclose($output_file);

但是,我还在等待某人提供更好的解决方案。

1 个答案:

答案 0 :(得分:0)

您在变量中有2个美元符号:

 fwrite($output_file, $$csv[0]."\r\n");
相关问题