Jump to content
Jack_mcs

Cron Simulator

Recommended Posts

This is the support thread for the Cron Simulator contribution. Cron is a program supplied by the host that allows a script to be ran at a preset time. Many osCommerce contributions make use of Cron but not all hosts offer it so those contributions can't be used to their fullest potential on such servers. The purpose of this contribution is to simulate a Cron job. Code is added to the index page of your admin and when it is loaded, the enabled jobs are checked and ran, if it is their time to be ran. This isn't as accurate as a real Cron job but it will run the script automatically, which is what is needed. This contribution is compatible with all versions of osCommerce.

Edited by Jack_mcs

Share this post


Link to post
Share on other sites

This is the support thread for the Cron Simulator contribution. Cron is a program supplied by the host that allows a script to be ran at a preset time. Many osCommerce contributions make use of Cron but not all hosts offer it so those contributions can't be used to their fullest potential on such servers. The purpose of this contribution is to simulate a Cron job. Code is added to the index page of your admin and when it is loaded, the enabled jobs are checked and ran, if it is their time to be ran. This isn't as accurate as a real Cron job but it will run the script automatically, which is what is needed. This contribution is compatible with all versions of osCommerce.

 

 

Hello, very handy but can you please provide a basic help file on how to use your modification? As after I enter a script name, script location/filename and time it is not saving.

 

I just mean a basic example of what to put in each field.

 

Kind regards

Chris

Share this post


Link to post
Share on other sites

Hello, very handy but can you please provide a basic help file on how to use your modification? As after I enter a script name, script location/filename and time it is not saving.

 

I just mean a basic example of what to put in each field.

- Run - if checked, run the script

- Script Name - some arbitrary name that allows you to identify the script

- File Name - name of the script to be ran, like googlefeeder.php

- Time To Run - the time the script should be ran (only happens if index.php is visited so may not be accurate)

- Frequency - should it be ran daily, weekly or monthly?

Share this post


Link to post
Share on other sites

- Run - if checked, run the script

- Script Name - some arbitrary name that allows you to identify the script

- File Name - name of the script to be ran, like googlefeeder.php

- Time To Run - the time the script should be ran (only happens if index.php is visited so may not be accurate)

- Frequency - should it be ran daily, weekly or monthly?

 

Ok thanks, Im thinking I might have some kind of issue then as I entered in the fields:

 

google base feed | googlefeeder.php(variations of path too) | 12 | weekly |

 

I click update and its not saved.

 

Im thinking maybe "tims safer database input mod" might have to be removed, not sure!

Share this post


Link to post
Share on other sites

Ok thanks, Im thinking I might have some kind of issue then as I entered in the fields:

 

google base feed | googlefeeder.php(variations of path too) | 12 | weekly |

 

I click update and its not saved.

 

Im thinking maybe "tims safer database input mod" might have to be removed, not sure!

I just tried entering

 

test | admin/test.php | 12 | weekly

 

and it saved correctly. The time (12) needs to be in military time (1200) but otherwise I don't see a problem. Are you sure the new entry isn't in the dropdown list?

Share this post


Link to post
Share on other sites

I did as you said and it does not work, its not in the database as I checked in phpmyadmin also.

Hmm, I don't have an answer for you then. The code that adds the entries in the admin is just standard code used in many of my contributions. There must be something in your shop or on the server that is preventing it from working but I've no way to isolate that in a thread like this. If you are able to set up a clean shop, I suggest installing it into it to isolate the problem.

Share this post


Link to post
Share on other sites

Yeah its really weird, It just refuses to save on a rc2a shop. The update button seems to react just like a refresh browser page button.

 

I removed the modifications added by tims safer database input method (installation file is wrong anyway)... same thing!

Share this post


Link to post
Share on other sites

Yeah its really weird, It just refuses to save on a rc2a shop. The update button seems to react just like a refresh browser page button.

 

I removed the modifications added by tims safer database input method (installation file is wrong anyway)... same thing!

 

Jack I'm having the same problem with this. When I check the database I can't help but notice that there is no index for that table. I don't know if one is needed or not but I wonder if that is preventing the data from being saved?

 

Dan

Share this post


Link to post
Share on other sites

Jack I'm having the same problem with this. When I check the database I can't help but notice that there is no index for that table. I don't know if one is needed or not but I wonder if that is preventing the data from being saved?

No, an index, or lack of one, shouldn't make it fail. It is possible that something is wrong in the code but it works fine in my test shop and on the site I created it for. What versions of php and mysql are you using? Maybe that has something to do with it.

Share this post


Link to post
Share on other sites

No, an index, or lack of one, shouldn't make it fail. It is possible that something is wrong in the code but it works fine in my test shop and on the site I created it for. What versions of php and mysql are you using? Maybe that has something to do with it.

Lets see...MySQL 5.0.77 and PHP 5.2.10...dan

Share this post


Link to post
Share on other sites

The versions should be OK. Please try this. In admin/cron_simulator.php, find

  if (tep_not_null($action))   { 

     if (isset($_POST['update_cron_x'])) { 

and change it to

  ?> <pre> <?php
 print_r($_POST);
 ?> </pre> <?php
 if (tep_not_null($action))   { 
 echo 'action found<br>';
     if (isset($_POST['update_cron_x'])) { 
     echo 'update pressed<br>';

Try updating and post the displayed results here.

Share this post


Link to post
Share on other sites

The versions should be OK. Please try this. In admin/cron_simulator.php, find

  if (tep_not_null($action))   { 

     if (isset($_POST['update_cron_x'])) { 

and change it to

  ?> <pre> <?php
 print_r($_POST);
 ?> </pre> <?php
 if (tep_not_null($action))   { 
 echo 'action found<br>';
     if (isset($_POST['update_cron_x'])) { 
     echo 'update pressed<br>';

Try updating and post the displayed results here.

 

I get this following Jack...

 

Array

(

[action] => process

[enabled_in] => on

[script_name_in] => AS_SiteMap

[file_name_in] => /googlesitemap/index.php

[time_to_run_in] => 1259

[frequency_in] => Daily

[scripts] => Select a Con Job

[update_cron_x] => 41

[update_cron_y] => 11

)

 

Dan

Share this post


Link to post
Share on other sites

OK. Remove those changes and replace this line

if (tep_not_null($action))   { 

with

  if (isset($_POST['action']) && $_POST['action'] == 'process') {

 

This is what happens when they let me out of the home around the holidays. :)

Share this post


Link to post
Share on other sites

OK. Remove those changes and replace this line

if (tep_not_null($action))   { 

with

  if (isset($_POST['action']) && $_POST['action'] == 'process') {

 

This is what happens when they let me out of the home around the holidays. :)

That did it Jack...it is now saving the cron job...the problem I'm now having is that it's not finding the file to be executed. I'm trying to set up a cron for your Google Site Map but when I enter either googlesitemap/index.php or /googlesitemap/index.php it can't find the file....I can execute it from the url command line but the cron module says that it can't find the file....does the file name need to be specified in any special way?

 

Dan

Share this post


Link to post
Share on other sites

That did it Jack...it is now saving the cron job...the problem I'm now having is that it's not finding the file to be executed. I'm trying to set up a cron for your Google Site Map but when I enter either googlesitemap/index.php or /googlesitemap/index.php it can't find the file....I can execute it from the url command line but the cron module says that it can't find the file....does the file name need to be specified in any special way?

 

Dan

You have to enter in the full path, like /home/username/public_html/script_name.php. Also, if the path is too long, which it probably will be, you will need to alter the size of the field in the database with this command

ALTER TABLE `cron_simulator` CHANGE `file_name` `file_name` VARCHAR( 256 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ;

Share this post


Link to post
Share on other sites

You have to enter in the full path, like /home/username/public_html/script_name.php. Also, if the path is too long, which it probably will be, you will need to alter the size of the field in the database with this command

ALTER TABLE `cron_simulator` CHANGE `file_name` `file_name` VARCHAR( 256 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ;

That sorted that Jack but now I seem to be running into functions that have already been declared...got this message when it tried to run the googlesitemap/index.php cron job....

 

Fatal error: Cannot redeclare tep_not_null() (previously declared in /xxxx/xxxxxxxxx/xxxxx/xxxxx/xxxxx/domain.com/xxxxx/admin/includes/functions/general.php:284) in /xxxx/xxxxxxxxx/xxxxx/xxxxx/xxxxx/domain.com/googlesitemap/index.php on line 72

 

Dan

Share this post


Link to post
Share on other sites

That sorted that Jack but now I seem to be running into functions that have already been declared...got this message when it tried to run the googlesitemap/index.php cron job....

 

Fatal error: Cannot redeclare tep_not_null() (previously declared in /xxxx/xxxxxxxxx/xxxxx/xxxxx/xxxxx/domain.com/xxxxx/admin/includes/functions/general.php:284) in /xxxx/xxxxxxxxx/xxxxx/xxxxx/xxxxx/domain.com/googlesitemap/index.php on line 72

 

Dan

Jack would you happen to know if this is a problem on my end or if something isn't quite right with the cron simulator?

 

Dan

Share this post


Link to post
Share on other sites

Jack would you happen to know if this is a problem on my end or if something isn't quite right with the cron simulator?

 

Dan

I'm sorry. I somehow missed your previous post. That is happening because the function tep_not_null has already been declared in admin and it can't be declared again. I don't know if there is a simple fix for that. You could add the code that you add to the admin/index.php file to the includes/footer.php (the other changes would be needed on the shop sitde too) but that would cause a delay whenever the script was ran and it would have to be edited to hide the output so that is not a good solution. I'll have to think on this but short of editing the googlesitemap file, I can't think of a good way around it.

Share this post


Link to post
Share on other sites

I'm sorry. I somehow missed your previous post. That is happening because the function tep_not_null has already been declared in admin and it can't be declared again. I don't know if there is a simple fix for that. You could add the code that you add to the admin/index.php file to the includes/footer.php (the other changes would be needed on the shop sitde too) but that would cause a delay whenever the script was ran and it would have to be edited to hide the output so that is not a good solution. I'll have to think on this but short of editing the googlesitemap file, I can't think of a good way around it.

This is probably a dumb question Jack and if so, please forgive me but if it's already declared in admin/index.php does it need to be declared again in cron simulator or could we just delete the declaration of that function in the cron simulator? If not maybe we just need to rename it?

 

Dan

Share this post


Link to post
Share on other sites

This is probably a dumb question Jack and if so, please forgive me but if it's already declared in admin/index.php does it need to be declared again in cron simulator or could we just delete the declaration of that function in the cron simulator? If not maybe we just need to rename it?

It isn't being loaded by this contribution. When Cron Simulator is ran in admin. it loads in the application_top file, as any script in admin does. But when it tries to execute a scrit on the shop side, the shops side functions get reloaded by that script, causing the duplicate problem. The parts of the code causing the problem could be re-coded so it doesn't happen but that opens up big problem since any script ran that way would need to be rewritten and that doesn't make for a very usable contribution. The only way I can see around it without disrupting everything else is to rewrite the Cron Simulator script to run as a standalone script. But that removes the automatic process of running it so you might as well just run the scripts themselves manually. So as it stands now, scripts made to run from admin should work. Those made to run on the shop side may fail, depending upon how they are coded. I'll play around with it and post if I find a sensible solution.

Share this post


Link to post
Share on other sites

It isn't being loaded by this contribution. When Cron Simulator is ran in admin. it loads in the application_top file, as any script in admin does. But when it tries to execute a scrit on the shop side, the shops side functions get reloaded by that script, causing the duplicate problem. The parts of the code causing the problem could be re-coded so it doesn't happen but that opens up big problem since any script ran that way would need to be rewritten and that doesn't make for a very usable contribution. The only way I can see around it without disrupting everything else is to rewrite the Cron Simulator script to run as a standalone script. But that removes the automatic process of running it so you might as well just run the scripts themselves manually. So as it stands now, scripts made to run from admin should work. Those made to run on the shop side may fail, depending upon how they are coded. I'll play around with it and post if I find a sensible solution.

 

I got it...thanks for the explanation Jack.

 

Dan

Share this post


Link to post
Share on other sites

hi jack,

 

i need a cronjob in this format /mailhive.php?xyz=run

 

to run a cronjob for mailbeez ( http://www.mailbeez.com )

is there a posibility to do that with cronjob simulator?

i get an error "A valid file name is required" if i try to

 

an where can i delete cronjob entries? in the database i know

but is there a posibility to do directly from cronjob simulator?

 

:(

:(

 

greets

 

andy

post-263171-0-49135600-1314694894_thumb.jpg

Edited by trentano

Share this post


Link to post
Share on other sites

It should work if the script is placed in admin, as explained previously. Is that where it is located?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×