We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Can PHP be run within EE Cron tags? What am I doing wrong?

Development and Programming

bgarrant's avatar
bgarrant
356 posts
14 years ago
bgarrant's avatar bgarrant

Is it possible to run a php function within EE Cron tags? I can make it work, but it seems to ignore the cron tag restriction and run every time page is loaded. I have this setup in my template with PHP Output. I am using a windows IIS 7 server. Can I run this within EE Cron? The get URL is just a sample.

{exp:cron minute="1" hour="1" day="7,14,21,28" month"*"}

<?php>
$handle = fopen("http://domain.com/index.php?ACT=24&export;", "rb"};
fclose($handle);
<?php>

{/exp:cron} 

Does anyone know how I can do this? I don’t need the page to load in browser, I just need to ping it so the script will run. I just want it to fire one time on day 7, 14, 21, 28. I am trying to hit a page to run a data export function. Is there a better way to do this? I can’t run cron on server so I want to use EE Cron. I know there are other add ons for this, but I want to first try EE cron.

Thanks in advance

Bryan

       
bgarrant's avatar
bgarrant
356 posts
14 years ago
bgarrant's avatar bgarrant

Anyone ever tried to run PHP in a EE Cron like this to Ping a URL? Any other methods that would work with EE Cron?

       
bgarrant's avatar
bgarrant
356 posts
14 years ago
bgarrant's avatar bgarrant

Can anyone offer any insight on this question?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

I think this might be a parse order complication. You might be better off setting the cron at the server level. Do you have access to do that? If not, how about the ability to request the cron job setup from your hosting provider?

       
bgarrant's avatar
bgarrant
356 posts
14 years ago
bgarrant's avatar bgarrant

Unfortunately this host does not allow scheduled tasks to be setup. It is windows hosting. Any way to make this work with EE Cron or another add-on? The EE Cron would work well if PHP would not parse on every load. It is almost like the EE Cron is parses after the PHP. Anyway other way to ping a page? Maybe AJAX?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team
Unfortunately this host does not allow scheduled tasks to be setup.

Ah, okay. Bummer.

The EE Cron would work well if PHP would not parse on every load. It is almost like the EE Cron is parses after the PHP.

I believe this is a parse order issue. One potential solution might be to move your PHP into a custom EE plugin. I think this would cause your plugin’s exp tag to get parsed after the cron tag is parsed.

       
bgarrant's avatar
bgarrant
356 posts
14 years ago
bgarrant's avatar bgarrant

Thanks Erik. I have never written a plugin. Is it easy to do? Any samples you may know of I can reference? What if I placed the PHP code in an embed or snippet, then place within the EE Cron tags?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team
Thanks Erik. I have never written a plugin. Is it easy to do? Any samples you may know of I can reference?

You could read the plugin tutorial in the EE docs: http://ellislab.com/expressionengine/user-guide/development/plugins.html Alternatively, I have a tutorial on Nettuts+ based on EE1 plugins. It’s very similar with a few tiny changes: http://net.tutsplus.com/tutorials/cmss/building-your-first-expressionengine-plugin/ Lastly, you could kickstart the code by using a tool built by a few members of the EE dev team: http://pkg.io

What if I placed the PHP code in an embed or snippet, then place within the EE Cron tags?

A snippet wouldn’t change anything, and I don’t think the embed would either. I suppose it’s worth a try though 😊

       
bgarrant's avatar
bgarrant
356 posts
14 years ago
bgarrant's avatar bgarrant

Thanks Erik. I will try that next to see how it works.

       
Tom Jaeger's avatar
Tom Jaeger
497 posts
14 years ago
Tom Jaeger's avatar Tom Jaeger

I would agree with Eric that the best route would be a plugin.

Alternatively you should be able to drop your PHP into an embed as EE calls the parser function for each embed.

-Tom

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.