vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Something strange about cronjobs (https://vborg.vbsupport.ru/showthread.php?t=75838)

Marco van Herwaarden 02-06-2005 03:46 PM

Something strange about cronjobs
 
After looking into some error reports on my Thread of the Week hack, i found the reason of the errors in some strange (in my eyes) behaviour of job run using the Scheduled Task Manager.

Test script 'includes/cron/test.php':
PHP Code:

<?php

error_reporting
(E_ALL & ~E_NOTICE);

if (!
is_object($DB_site))
{
    exit;
}


function 
test1()
{
    global 
$log$count;
    
$log .= "Line $count. Level: Function<br />";
    
$count += 1;
}

// global $log, $count;
$log "";
$count 1;

$log "Line $count. Level: Main<br />";
$count += 1;

test1();

$log .= "Line $count. Level: Main<br />";
$count += 1;

// Now let's write the log lines
log_cron_action($log$nextitem);

?>

Put this script in a file called 'test.php' in your 'includes/cron' directory.

Now add a new Task with the Scheduled Task Manager, pointing to this file, set it to log the action.

If you now press "Run Now" and look at the lines written into the Scheduled Task Log. It will look like this:
Code:

134 test 18:34, 6th Feb 2005
Line 1. Level: Main
Line 2. Level: Function
Line 3. Level: Main

This is what i expected the script to do, all look ok. I set variable "$count" to the value "1" in the main line and add a line to "$log". Still in the main i add 1 to the counter and i call the function test1.

In function test1 i set the vars $log and $count to global, thus giving me access to the same vars as used in the mainline. I again add a line to the $log and increase $counter. Now return to mainline.

Back in the main line $counter still contain the value as set in the function, and $log now contain 2 lines. I add 1 more line, write $log to the Scheduled Task log and finish.

This is exactly what happens when i run it with the "Run Now" button.

Now i repeat the test, but this time i let it run automatic, by setting a time for the Task to run. I wait till it has run, and go look in the Scheduled Task Log.

I expect exactly the same output, since it is the same script.

But, output is as follows:
Code:

138 test 18:44, 6th Feb 2005
Line 1. Level: Main
Line 2. Level: Main

No output from lines added in the function. The global in the function didn't give me access to the vars used in the mainline.

What am i missing here?

PS Yes when i also in the main line declare these 2 vars as global, or if i would pass them as parameters to the function, i could make this work. But that is not the point. I just want to understand what is going on.

Marco van Herwaarden 02-07-2005 04:21 PM

Hmm a tiny bump?

Marco van Herwaarden 02-09-2005 05:36 AM

Nobody got an opinion about this??

PS Maybe if a Mod would move it to the "PHP / MySQL / JS / (X)HTML" section, although i think it more belongs here.

Bee-Baa-Bumper

Marco van Herwaarden 02-11-2005 07:49 AM

Bumperty, Bumperty, Bump

Really nobody?

miz 02-11-2005 11:27 AM

hmm can you explain in 2 line what exsacly are you tring to do ?

Marco van Herwaarden 02-11-2005 06:31 PM

Well put shortly: In the main line i define a variable $var, assign a value to it, i call a function. In that function i do a "global $var;", assign a new value to $var and return to main.

If i run this with "Run Now", all go like expected: $var gets assigned in main, after the "global $var" i can in the function access the value set in the mainline, and on return to mainline, i still have the new value set in the function.

If run through the scheduler however, this will not pass the value of $var to the function or back to the mainline.

PS Sorry 3 lines :D

Marco van Herwaarden 02-14-2005 02:33 PM

Time for a small bump i think

noppid 02-14-2005 04:23 PM

I too have found this to be the case. I am writing a scheduled task as we speak and it's just not running. Existing vB scheduled tasks run fine. Mine runs fine from the run now button, but it does absolutly nothing on schedule.

I read threads at vBulletin.com and it seems they are not giving anyone that points this out any more then the answer that it works.

But it don't.

Marco van Herwaarden 02-15-2005 05:04 AM

Yes i know it doesn't work as you would expect. Took me a long time and the help of a frustrated user of my Thread of the Week hack to find out what was "wrong"

If you need help with your cronjob, let me know. Think i know now what to look for.

noppid 02-15-2005 05:06 AM

Quote:

Originally Posted by MarcoH64
Yes i know it doesn't work as you would expect. Took me a long time and the help of a frustrated user of my Thread of the Week hack to find out what was "wrong"

If you need help with your cronjob, let me know. Think i know now what to look for.


Actually, I got mine working after I posted. I don't give up easily! Thanks for your input though.

My problem was exactly that, my problem. The thing works as intended. I'm not sure about all of it, but I got the job done.

Marco van Herwaarden 02-15-2005 09:50 AM

I not tried posting this on vb.com or as a bug yet, thought i could first get the opinion of some fellow coders on it.

But because of the lack of response in here, and teh confirmation from noppid that i am not alone on this, i think i will try it with a bug report and see what reaction i get.

James T Brock 02-15-2005 04:50 PM

The scheduled task script in vB appears to be just for simple stuff and rarely seems to work correctly when incorporated into mods. I have the NNTP gateway script included on my site and it would only partially work (would recieve usenet posts fine but wouldn't send out any) so instead of using the scheduled task manager I just used real cronjobs. Now it works perfectly.

I don't know why this is the case, just letting you know other hack authors have had the same problem.

Marco van Herwaarden 02-15-2005 07:26 PM

Then i think it is about time we do something :D

Slave 03-10-2006 01:07 PM

Did you ever report this MarcoH64? .. I can't find the bug report if you did.

Marco van Herwaarden 03-10-2006 01:15 PM

I think there was (in the vB3.0 bug reports)

Slave 03-10-2006 01:28 PM

Ahh .. didn't see the date of the thread .. I was looking in the 3.5 bugs ..

Reason I ask is that I'm seen a similar problem with a cron job for a hack, where it works fine if "run now" and yet when it runs at the time set it says its run correctly in the logs but it seems only some of the script runs ..

You said above you know what to look for .. is it something obvious, or is it something deeper you need to add to the code?

Marco van Herwaarden 03-10-2006 01:32 PM

Are you using functions in your script that rely on global variables?

PS That bugreport was closed with a "Working as Designed" if i remember correct.

jwocky 06-01-2006 02:25 PM

Rehashing an old thread, I have the same exact problem and found that the global variables were the key. Is there a solution to this short of moving all my global variables into the individual processes ? (pain! :)


All times are GMT. The time now is 08:58 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01151 seconds
  • Memory Usage 1,760KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (18)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete