我的代码一直在工作,直到我将 node.js 更新到版本 8.11.3
现在,当我尝试使用 setTimeout 调用函数时,总是收到错误“回调参数必须是函数”。
function testFunction(itemid, price) {
var url = 'https://example.com';
var options = {
method: 'get',
url: url
}
request(options, function (err, res, body) {
var response = JSON.parse(body);
if(response.status == 'fail'){
setTimeout(testFunction(itemid, price), 100);
}
})
}
Run Code Online (Sandbox Code Playgroud) 我试图从test_bots.json中取消设置值并将其保存回来,但不知何故,数据格式在此过程中正在被更改.
test_bots.json包含此JSON数组:
["John","Vladimir","Toni","Joshua","Jessica"]
Run Code Online (Sandbox Code Playgroud)
我的代码看起来像这样:
$good = 'Toni';
$good_arr = file_get_contents('test_bots.json');
$good_arr = json_decode($good_arr);
if(in_array($good, $good_arr)){
$key = array_search($good, $good_arr);
unset($good_arr[$key]);
$good_arr2 = json_encode($good_arr);
file_put_contents('test_bots.json',$good_arr2);
}
Run Code Online (Sandbox Code Playgroud)
保存的输出是:
{"0":"John","1":"Vladimir","3":"Joshua","4":"Jessica"}
Run Code Online (Sandbox Code Playgroud)
但我希望输出看起来像:
["John","Vladimir","Joshua","Jessica"]
Run Code Online (Sandbox Code Playgroud)
我尝试在保存数组之前反序列化数组,但它不起作用.
为什么会这样?
每次我file_put_contents
在 DigitalOcean 的 LAMP 服务器上的 PHP 脚本中使用时,都会收到以下错误消息:
file_put_contents(test_digitalocean.json): failed to open stream:
Permission denied in /var/www/html/test_digitalocean.php
Run Code Online (Sandbox Code Playgroud)
如何正确设置权限?
我通过/test_digitalocean.php
在浏览器中输入服务器的 IP 地址来访问我的脚本。
所有脚本都上传到 /var/www/html/
如果我查看 FileZilla 中的 www 文件夹,我可以看到权限为 775,所有者和组都为 www-data。