Jump to content
php.lv forumi

Cron


Manson

Recommended Posts

Привет! Вобщем есть такой скрипт. Висит как daemon, в процессах и что-то вроде крона - запускает скрипты каждую секунду. Но на каждый скрипт нужно свое время запуска! Подскажите пожалуста как это сделать

 

#! /usr/local/bin/php
<?php
	$uptime = microtime(1);
	set_time_limit(0);
	error_reporting(E_ALL);

	$_GET['cwd'] = dirname(__FILE__);
	# Pid
	if (FALSE == array_search ('nopid', $argv)) $pid = posix_getpid();
	else $pid = 0;

	echo "\n".'Ok, pid='.$pid;
	$f2=fopen($_GET['cwd']."/btl.pid","r");							  
	flock($f2,2);			
	$f=fopen($_GET['cwd']."/btl.pid","w+");
	fputs($f, $pid);	
	fclose($f);			  
	flock($f2,3);			
	fclose($f2);

	# /Pid

	# libs  
	include ($_GET['cwd']."/dco/vars.dco");
	include ($_GET['cwd']."/dco/gun_lev.dco"); // + gren_lev()
	include ($_GET['cwd']."/dco/lvl_p.dco");
	include ($_GET['cwd']."/dco/nicks_bot.dco");
	include ($_GET['cwd']."/dco/end_btl_bot.dco");
	include ($_GET['cwd']."/dco/bot_atak.dco");
	include ($_GET['cwd']."/dco/btl_bot.dco");
	include ($_GET['cwd']."/dco/btl.dco");
	include ($_GET['cwd']."/dco/btl_die.dco");
	include ($_GET['cwd']."/dco/nicks.dco");
	include ($_GET['cwd']."/dco/end_btl.dco");
	include ($_GET['cwd']."/dco/steps.dco");
	include ($_GET['cwd']."/dco/req_g_btl.dco");
	include ($_GET['cwd']."/dco/bot_name.dco");
	include ($_GET['cwd']."/dco/req_bot.dco");
	include ($_GET['cwd']."/dco/req_btl.dco");
	include ($_GET['cwd']."/dco/hp_rec.dco");
	include ($_GET['cwd']."/dco/cron.dco");
	include ($_GET['cwd']."/dco/job_end.dco");
	include ($_GET['cwd']."/dco/out.dco");
	include ($_GET['cwd']."/dco/chat.dco");
	include ($_GET['cwd']."/dco/word.dco");
	# include ("dco/mysql_d_connect.dco");
	# /libs

	echo "\n".'Libs -- OK';
	# if (mysql_pconnect(':/tmp/mysql.sock', 'asd', 'dsa')){
	if (mysql_connect('localhost','baza','parolj')){
			echo "\n".'MySQL -- OK';
	}	

	## start deamon ##
	$x = 0;
	echo "\nStart\n";
	while (true) {
			while (@mysql_ping()===FALSE) {
					echo "MySQL connect false\n";
					sleep(10);
					$mysql_ping++;
			}
			$loops++;
			steps ();		
			####
			req_g_btl();
			req_bot();
			req_btl();
			cron();	
			####
			$res  = mysql_query("SELECT stat FROM geo.stat ");
			$stat = mysql_fetch_row($res);
			if ($stat[0] == 2)
					break;
			sleep(1);
			if (FALSE != array_search ('one', $argv))
					break;
	}	
	##
	$uptime = microtime(1) - $uptime;
	echo "\nbtl.dd be stoped!\nLoops = $loops\nMySQL reconnects = $mysql_ping\nUptime=$uptime";
?>

Link to comment
Share on other sites

×
×
  • Create New...