cron job won't write to file

2019-05-03 11:11发布

I run a windows 2003 server and tried to run a code like this every 15 minutes:

require("db_connect.php");
$conn = db_connect();

//list online brukere - flytt funksjon til separat side for bedre ytelse
$time = time() - 900;
$query ="SELECT username FROM tbl_user WHERE last_online >= $time";
$online_users; 
if ($result = $conn->query($query)) {
    while ($row = $result->fetch_assoc()) {
        $online_users .= $row["username"].":";
    }
    $result->close();
}   

$filename = "online_users.txt";
$fp = fopen($filename,"w");
fputs($fp,$online_users);
fclose($fp);

When I go to the url or run it from the command line it works and write to file. But the task just run and don't save the file.. What's wrong?

2条回答
成全新的幸福
2楼-- · 2019-05-03 11:28
$filename = dirname(__FILE__) . "/online_users.txt";
查看更多
你好瞎i
3楼-- · 2019-05-03 11:31
$filename = "online_users.txt"; <-- this is using relative path

You might not have permission to write to relative path.

So, chose another path with enough write permission, and please, use absolute path instead.

查看更多
登录 后发表回答