在項目過程中,需要程序日誌記錄重要數據,當然首選使用json來記錄數據,將對象進行相應的json編碼後,使用file_put_contents將數據持久化,但是總提示我權限不足,折騰了一陣後,只得去雲平臺論壇去搜索,果然有相關的問題,先總結如下:
(1)動態的文件創建在sae裏面是不可能的!包括數據表的動態建立;
(2)數據持久化,sae給出瞭解決方案,在左側的服務中有storage服務,可以進行file的寫入
使用可以參考api文檔:
http://apidoc.sinaapp.com/class-SaeStorage.html
我給出兩個我項目中的例子
1.讀
function loadcurrentdatelog()
{
$storage=new SaeStorage();
$domain='myjson';
$filename='currentdatelog.json';
$currentlogcontent=$storage->read($domain,$filename);
return json_decode($currentlogcontent,true);
}
2.寫
function updatecurrentdatelog($currentlogstring)
{
$storage=new SaeStorage();
$domain='myjson';
$filename='currentdatelog.json';
$result=$storage->write($domain,$filename,$logstring);
}
呵呵,也挺方便吧,不過,這些限制總是不讓人不舒服。
題外話:在SAE部署計劃任務時,我使用php script 通過exec來執行crontab,也是不明不白的報錯,看了官方文檔後,此類系統級操作都是禁用的,但是SAE雲平臺同樣提供了CRON服務,也在服務那一列,我們只需按照例子格式添加到xxx.yaml就可以配置計劃調度了,可以說也算方便!