Forums / Developer / Run cronjobs on demand?

Run cronjobs on demand?

Author Message

Jorge estévez

Monday 22 March 2010 5:50:16 am

Hello to all,

Instead of waiting to run cronjobs.php at a defined time I would like to run it on demand? Is this possible from a browser (admininstration site).

Thanks

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

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

eZ debug

Timing: Jan 17 2025 23:35:33
Script start
Timing: Jan 17 2025 23:35:33
Module start 'content'
Timing: Jan 17 2025 23:35:33
Module end 'content'
Timing: Jan 17 2025 23:35:33
Script end

Main resources:

Total runtime0.1248 sec
Peak memory usage4,096.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0078 587.6875180.8438
Module start 'content' 0.00780.0058 768.5313109.9609
Module end 'content' 0.01370.1110 878.4922537.7500
Script end 0.1247  1,416.2422 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00322.5817200.0002
Check MTime0.00131.0439200.0001
Mysql Total
Database connection0.00110.919910.0011
Mysqli_queries0.084467.60051410.0006
Looping result0.00110.88151390.0000
Template Total0.110888.810.1108
Template load0.00070.539310.0007
Template processing0.110188.188910.1101
Override
Cache load0.00050.369510.0005
Sytem overhead
Fetch class attribute can translate value0.00100.781410.0010
XML
Image XML parsing0.00020.197910.0002
General
dbfile0.00383.0324200.0002
String conversion0.00000.005030.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs