Execute the PHP code under the zendframework framework under the Linux Command Line

Source: Internet
Author: User

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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.