2016-06-08 146 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' –