Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Set Cron in Zend Framework?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.49k
    Comment on it

    In order to set cron in zend framework please follow the below steps.

    Step 1: Please do not execute or access the bootstrap's run function directly in the file index.php

    Location of file : public_html/index.php

    Now Upgrade below code:

    if (php_sapi_name() != 'cli' || !empty($_SERVER['REMOTE_ADDR'])) {
     $application->bootstrap()->run();
    }
    

    Step 2: Now Create a folder inside root folder of web application named as cronjob.

    Step 3. Create a new file named as init.php inside the cronjob folder and add below code over there.

     // Define path to application directory
        defined('APPLICATION_PATH')
                || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
    
    // Define application environment
    defined('APPLICATION_ENV')
            || define('APPLICATION_ENV', 'environment');
    
    // Ensure library/ is on include_path
    set_include_path(implode(PATH_SEPARATOR, array(
                realpath(APPLICATION_PATH . '/../library'),
                get_include_path(),
            )));
    
    /** Zend_Application */
    require_once 'Zend/Application.php';
    
    // Create application, bootstrap, and run
    $application = new Zend_Application(
                    APPLICATION_ENV,
                    APPLICATION_PATH . '/configs/application.ini'
    );
    $application->bootstrap();
    

    Step 4:OK.Now Create one more file named as mycron.php under the cronjob folder.

    Add below code in mycron.php file

    require_once 'init.php';
    print_r($_SERVER);
    

    Step 5.Also add followintg code in mycron.php.

    Now, you have access for all the models like this :

    $obj = new Application_Model_Logs();
    

    This is the file where you can access all global variable of zend's and not only variable even you can access all the models files as same as we had used there in controller section.

    Step 6: Now for testing the cron use this command

    Login using putty and go to the path of folder where PHP installed and after then run below code.

    php C:\wamp\www\myproject\cronjob\mycron.php 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: