I have been using zendframework for some time and feel it is easy to use it for development. Recently, I need to regularly execute a PHP script in Linux. After referring to the framework structure of the project, write this script (some of the business-related functions in the following script are omitted) and run it in crontab. It is normal. Write a log to write down, PHP projects do not touch every day, afraid to forget.
<? PHP
$ Root = dirname (_ file __));
$ Dumpdir = "$ root/dump ";
$ Listfile = "$ dumpdir/list.csv ";
If (! File_exists ($ listfile )){
Echo "Please check list.csv file exist under dump directory ";
Return;
}
$ Lib = "$ root/library ";
$ APP = "$ root/Application ";
Set_include_path ($ Lib. path_separator. $ app. path_separator. get_include_path ());
Require_once 'zend/loader. php ';
Zend_loader: registerautoload ();
$ Config = new zend_config_ini ("$ APP/config/install. ini ");
If (! Empty ($ config-> database )){
$ Datasource = $ config-> database-> main;
} Else {
Throw new scarab_exception_config ('the DSN is not configured while using the database! ');
}
$ Db = zend_db: Factory ($ datasource );
Zend_registry: Set ('db', $ dB );
$ Db-> query ("set names utf8 ");
$ Date = new zend_date (null, 'zh _ cn ');
Require_once "$ APP/CORE/models/synchronization. php ";
Require_once "$ APP/CORE/models/Tables. php ";
$ Sync = new sync ();
$ Personlist = parsefile ($ listfile );
Try {
Foreach ($ personlist as $ item ){
$ From = new zend_date ($ item [1], 'Y-m-d ');
$ To = new zend_date ($ item [2], 'Y-m-d ');
If ($ from-> compare ($ to)> 0 ){
Continue;
}
While ($ from-> compare ($ to) <0 ){
$ Fromstr = $ from-> tostring ('Y-m-dd ');
$ From-> Add ('1', zend_date: Day );
$ Fromstr _ = $ from-> tostring ('Y-m-dd ');
$ Dataofhour = $ sync-> getappxml ($ permid, $ fromstr, $ fromstr _);
If (! Empty ($ dataofhour )){
$ Sync-> savetofile ($ dataofhour, "$ dumpdir/$ name/export fromstr.hour.csv ");
}
$ Dataofminute = $ sync-> getappdataxml ($ permid, $ fromstr );
If (! Empty ($ dataofminute )){
$ Sync-> savetofile ($ dataofminute, "$ dumpdir/$ name/export fromstr.minute.csv ");
}
}
}
} Catch (zend_db_exception $ e ){
Echo $ e-> getmessage ();
}