2016-06-08 102 views
0

我试试这个:PHP的cron FWRITE不工作

<?php 
$time = time(); 
$fh = fopen("cron.txt", 'a+'); 
fwrite($fh, $time); 
echo "ok"; 
?> 

对SSH运行:

/opt/bitnami/php/bin/php /opt/bitnami/apache2/htdocs/cron.php 

和远程服务器:

budzinski.xyz/cron.php 
在localhost

它工作正常,在远程服务器和cron上,不要

+0

是共享主机,他们是否禁用了allow_url_fopen? http://php.net/manual/en/filesystem.configuration.php“如果启用了fopen包装,你只能使用fopen()来访问远程文件。该参数在php.ini文件中指定,不能更改在运行时使用ini_set“ – ArtisticPhoenix

+0

有没有关于错误的任何信息? – John

+0

是自配置在AWS上bitnami服务器上的php.ini它具有: 了allow_url_fopen =在 这表明没有错误 –

回答

0

你的cron命令需要修改像这个 - :文件的

/opt/bitnami/php/bin/php /home/[yourcpanelname]/[your patht to the file]/cron.php 
+0

好吧,我将它改为:/ opt/bitnami/php/bin/php /home/bitnami/htdocs/cron.php你认为php目录可能不好? –

0

检查的权限为可写或不 尝试这个例子,不是看你是否得到任何输出或不

<?php 
$filename = 'test.txt'; 
$somecontent = "Add this to the file\n"; 

// Let's make sure the file exists and is writable first. 
    if (is_writable($filename)) { 

// In our example we're opening $filename in append mode. 
// The file pointer is at the bottom of the file hence 
// that's where $somecontent will go when we fwrite() it. 
if (!$handle = fopen($filename, 'a')) { 
    echo "Cannot open file ($filename)"; 
    exit; 
} 

// Write $somecontent to our opened file. 
if (fwrite($handle, $somecontent) === FALSE) { 
    echo "Cannot write to file ($filename)"; 
    exit; 
} 

echo "Success, wrote ($somecontent) to file ($filename)"; 

fclose($handle); 

    } else { 
    echo "The file $filename is not writable"; 
    } 
?> 
+0

成功,写到(添加到文件中)到文件(cron.txt)但仍然是我的cron不工作 –

+0

尝试打开文件模式a而不是+这样 - :fopen($ filename,'a') –

+0

ok我更改为'a' –