vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Only allowing a script to run once at a time... (https://vborg.vbsupport.ru/showthread.php?t=217163)

m002.p 06-26-2009 08:07 AM

Only allowing a script to run once at a time...
 
Hi everyone,

I have a script that runs every 3 seconds kickstarted by CRON every minute. I want to however stop the script overlapping itself as it sometimes does, so in short, I would like to only allow it to run once per time.

So I formulated a method without using MYSQL, a simple .txt file check as follows. The only issue is sometimes it forgets to remove the file so I end up with a script not running at all. In addition it places these files in the very root of the server not in the directory the script runs. Could this be something to do with it?

PHP Code:

<?php
$fileN 
"check.txt";
$filename '/public_html/serverchecks/$fileN';

if (
file_exists($filename)) {
    exit();

}else{

$ourFileHandle fopen($fileN'w') or die("can't open file");
fclose($ourFileHandle);

}

// Script code HERE

unlink($fileN); 

?>

Any ideas?

Thanks in advance.

Matt

jchamber2010 06-27-2009 01:46 AM

PHP Code:

<?php
$fileN 
"check.txt";
$filename "/public_html/serverchecks/$fileN";

if (
file_exists($filename)) {
    exit();

}else{

$ourFileHandle fopen($filename'w') or die("can't open file");
fclose($ourFileHandle);

}

// Script code HERE

unlink($filename); 

?>

That should work now, you were using the wrong variable... I think, however I haven't time to test it, so hope that works for you.

Dismounted 06-27-2009 04:53 AM

PHP Code:

$filename '/public_html/serverchecks/$fileN'

That is not going to work. This file never exists because the path is going to be literally read. As you are using single quotes, the variable is not substituted into the sting. Use double quotes or concatenate.


All times are GMT. The time now is 12:20 AM.

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.00930 seconds
  • Memory Usage 1,719KB
  • 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
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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