上述问题有时才会发生。我不知道为什么,但我假设我的php脚本(用于在JSON文件中保存和加载JSON对象)并没有完美地完成。
writeLanguage.php
<?php
$myFile = "languages.json";
$cmsData = $_POST['data'];
$obj = json_decode($cmsData, true);
$myFile = "language.json";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh,json_encode($obj));
fclose($fh);readLanguage.php
$cmsData = $_GET['data'];
$myFile = "language.json";
$fhh = fopen($myFile, 'r') or die("can't open file");
$jsondata = file_get_contents($myFile);
fclose($fhh);
$json = json_decode($jsondata, true);
echo $jsondata;在这里,我的javascript代码:
DataService.prototype.loadLanguagePromise = function () {
return new Promise(function (resolve, reject) {
$.ajax({
url: "php/services/readLanguage.php",
type: "GET",
async: true,
dataTyp: 'json',
success: function (data) {
resolve("stuff worked");
},
error: function (xhr, desc, err) {
reject(Error("It broke"));
}
})
})
};
DataService.prototype.saveLanguage = function (cmsObject) {
return new Promise(function (resolve, reject) {
$.ajax({
url: "php/services/writeLanguage.php",
type: "POST",
data: {data: JSON.stringify(cmsObject)},
dataTyp: 'json',
success: function (data) {
resolve(data);
},
error: function (xhr, desc, err) {
reject(xhr, desc, err);
}
})
})
};我查了一下分段故障的定义,但没有真正得到“aaaaah.当然,这就是原因”。
发布于 2019-03-25 22:27:11
尝试删除fopen、fwrite和fclose。在第一种情况下,您只需要file_put_contents(),在第二只需要file_get_contents。
<?php
$myFile = "languages.json";
$cmsData = $_POST['data'];
$obj = json_decode($cmsData, true);
$fh = file_put_contants($myFile, $cmsData,LOCK_EX) or die("can't open file");$cmsData = $_GET['data'];
$myFile = "language.json";
$jsondata = file_get_contents($myFile);
$json = json_decode($jsondata, true);
echo $jsondata;发布于 2021-10-11 15:11:32
在https://stackoverflow.com/a/7752606/4625150中使用答案对分割故障的系统分析
以上的一个将需要一些时间来找出,但你会找到正确的根源,然后解决它。
查看您的代码,您正在读取JSON,然后将JSON写入文件系统。这是一个故障区域,并多次由于内存不足。解决内存问题
https://stackoverflow.com/questions/55347252
复制相似问题