Share » Forums » Developer » Run cronjobs on demand?

Run cronjobs on demand?

Run cronjobs on demand?

Monday 22 March 2010 5:50:16 am - 10 replies

Author Message

Matthieu Sévère

Monday 22 March 2010 8:01:23 am

Hello,

Did you try to execute the following command :

php bin/php/ezexec.php path/to/your/cronjob_script.php

--
eZ certified developer: http://ez.no/certification/verify/346216

Jorge estévez

Monday 22 March 2010 9:06:46 am

Thanks

But how can this be excecuted from the browser? Can it be done? Is there any workaround?

The runcronjobs does "things" from time to time, If I wanted a recent update of things that the runcronjobs.php does it would be great to (from the admin page) run it and then get the expeted results right away instead of waiting for the time of excecution.

Thanks again!

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Matthieu Sévère

Monday 22 March 2010 9:45:25 am

Currently there is no way to achieve this in the administration site.

If you know a bit eZ Publish you can create a custom extension that adds a tab in the admin interface (see menu.ini) that trigger a view of a custom module to execute this command.

--
eZ certified developer: http://ez.no/certification/verify/346216

Jorge estévez

Monday 22 March 2010 12:13:55 pm

Thanks

 

Ok I know how to add the tab in the admin interface, The view of a custom module I can manage to make it, what I do not understand is how to achieve to make the runcronjobs.php work within a view of a module…

 

How can I make a view of a module that runs the cronjobs.php? I am missing the “how to” links that triggers the execution of the runcronjobs.php

thanks

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Matthieu Sévère

Monday 22 March 2010 1:15:58 pm

Just call this code in your view :

<span>exec("php bin<span>/</span>php<span>/</span>ezexec<span>.</span>php path<span>/</span>to<span>/</span>your<span>/</span>cronjob_script<span>.</span>php")</span>

It should execute the command like if you were in a unix shell and this should run your cronjob (you can also just run "php runcronjobs.php" to run all cronjobs)

--
eZ certified developer: http://ez.no/certification/verify/346216

Jorge estévez

Monday 22 March 2010 8:39:54 pm

Hello again, thanks for your tip, it has driven me to new ideas….
I have added a new tab at the admin making configurations at the menu.ini (not an extension)
I came up with something I hope will work, I added the following to the new tab menu definition (menu.ini):

[Topmenu_excel]  NavigationPartIdentifier=ezexcelnavigationpart  Name=Tablas de Excel  Tooltip=Export excel table  URL[]  # NOTICE THAT node is not important  URL[default]=content/view/excel/172   Enabled[]  Enabled[default]=true  Enabled[browse]=false  Enabled[edit]=false  Shown[]  Shown[default]=true  Shown[edit]=false  Shown[navigation]=true  Shown[browse]=true

I have added new view-mode of seeing nodes (excel) and within the new view-mode I added the code as you told me that generates:

 exec("php /bin/php/ezexec.php /runcronjobs.php")

but it does not work, maybe I have the path to the cronjobs.php wrong, anyway I run the following from the command prompt:

(this a complete line) c:/ezpublish/php/php c:/ezpublish/ezpublish/bin/php/ezexec.php
c:/ezpublish/ezpublish/runcronjobs.php –s (using default siteaccess)

and the output is :

 #!/usr/bin/env php
Running cronjob part 
'c:/ezpublish/ezpublish/runcronjobs.php'
Notice: No scripts found for
 execution.

So, ezexec runs but it seems runcronjobs.php is not doing anything at all if ran with the ezexec.php
Instead if I run the following (using php to execute runcronjobs.php directly)

 c:/ezpublish/php/php runcronjobs.php -dall -s

It works like a charm.
Any Ideas?

thanks again!

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Matthieu Sévère

Tuesday 23 March 2010 12:54:27 am

Yes of course, I suggested the use of ezexec if you want to launch a specific script (in a custom extension for example.) otherwise you need to launch directly runcronjobs.php

I don't understand all your mechanism how did you manage to create a new view without creating an extension?

--
eZ certified developer: http://ez.no/certification/verify/346216

Jorge estévez

Tuesday 23 March 2010 5:08:46 am

Thanks

A new view, just go to root/design/admin/template/node/view and create excel.tpl (I am using ezwebin)

indide I just added

 <span>exec("php bin<span>/</span>php<span>/</span>ezexec<span>.</span>php bin<span>/</span>dale<span>.</span>php")</span>

of course this could hve been a more complicated .tpl

The Tab was simply created reading menu.ini and seeing other examples in extensions

So there is no way I can make runcronjobs.php work?

at the prompt:

c:/ezpublish/php/php c:/ezpublish/ezpublish/bin/php/ezexec.php c:/ezpublish/ezpublish/runcronjobs.php –s

does not work, how can this be? Maybe this is the same case when executed from the template.

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Matthieu Sévère

Tuesday 23 March 2010 5:47:49 am

I think you really should create an extension and a module in which you can execute what php you want (espcially the exec function).

exec() should not be in a template.

--
eZ certified developer: http://ez.no/certification/verify/346216

Gaetano Giunta

Tuesday 23 March 2010 11:24:07 am

with some careful coding, you can write php scripts that can be run either via direct cli invocation or as a cronjob. You just need to add some code at beginning of script, similar to this:

<code>

if ( !defined('eZRunCronjobs_MaxScriptExecutionTime' ) )
{
set_time_limit ( 0 );
require 'autoload.php';
require_once('kernel/content/ezcontentfunctioncollection.php');
$cli = eZCLI::instance();
$cli->setUseStyles( true );
$CLI_FAILURE = $cli->style( 'failure' );
$CLI_FAILURE_END = $cli->style( 'failure-end' );
$CLI_SUCCESS = $cli->style( 'success' );
$CLI_SUCCESS_END = $cli->style( 'success-end' );
$CLI_NOTICE = $cli->style( 'notice' );
$CLI_NOTICE_END = $cli->style( 'notice-end' );
$script = eZScript::instance( array( //'description' => ( "description" ),
//'use-session' => true,
'use-modules' => true,
'use-extensions' => true ) );
$script->startup();
$script->initialize();
} else {
$CLI_FAILURE = '';
$CLI_FAILURE_END = '';
$CLI_SUCCESS = '';
$CLI_SUCCESS_END = '';
$CLI_NOTICE = '';
$CLI_NOTICE_END = '';
}
</code>

Principal Consultant International Business
Member of the Community Project Board

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu