Forum Moderators: coopster

Message Too Old, No Replies

sleep(), exec() and MySQL

timed actions and dynamically generated table

         

smarty

9:02 am on Jan 17, 2004 (gmt 0)

10+ Year Member



How to create dynamically generated table

time span 12:50:00 to 13:05:00

$start_time = 12:50:00;
$stop_time = 13:05:00;
$interval = 60;
$repeater = 2;

table ‘tasks’

id ¦ time ¦ code ¦ action ¦ status ¦ created ¦ lock
---------------------------------------------------------------------------------
3 ¦ 12:52:00 ¦ 303 ¦ action3.php ¦ idle ¦ 2004-01-17 12:45:00 ¦ false
2 ¦ 12:51:00 ¦ 202 ¦ action2.php ¦ idle ¦ 2004-01-17 12:45:00 ¦ false
1 ¦ 12:50:00 ¦ 303 ¦ action3.php ¦ done ¦ 2004-01-17 12:45:00 ¦ true

tasks
‘id=1’ $starttime (12:50:00)
‘id=2’ $starttime + $interval (60 seconds)
‘id=3’ last time (12:51:00) + $interval (60 seconds)

coopster

10:19 pm on Jan 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



smarty, could you offer a bit more information on what you want to accomplish? Is this data in a file and you want to extract it and display it in an HTML page as a <table>?

smarty

11:30 pm on Jan 18, 2004 (gmt 0)

10+ Year Member



No this is MySQL table.

coopster

1:02 am on Jan 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So you want to know how to INSERT [mysql.com] rows into this table with the data being described?

smarty

8:56 am on Jan 19, 2004 (gmt 0)

10+ Year Member



How to make this independence automation system (24hour/7day)?

Keywords: cron, crontab, exec()
Server: Apache, PHP, MySQL

MySQL tables

table ‘engine’

engineID ¦ status
- - - - - - - - - -
1 ¦ ON

next_start, processing_time and interval unit of time is second.

table ‘start_engine’
startID ¦ next_start ¦ processing_time
- - - - - - - - - - - - - - - - - - - - - - -
1 ¦ 60 ¦ 60
2 ¦ 300 ¦ 900
3 ¦ 1800 ¦ 900

‘actions’ is interval repeater

table 'processes'
processID ¦ interval ¦ actions
- - - - - - - - - - - - - - -
1 ¦ 60 ¦ 1
2 ¦ 60 ¦ 2
3 ¦ 1 ¦ 3
4 ¦ 5 ¦ 2

table ‘codes’
codeID ¦ code ¦ command
------------------
1 ¦ 101 ¦ action1.php
2 ¦ 202 ¦ action2.php
3 ¦ 303 ¦ action3.php

example:
if engine ‘ON’ then time now() + random(startID) + random(processID) + random(codeID)
time now is 12:49:00 + 60 sec = 12:50:00
next_start = 12:50:00

How to create dynamically generated table

time span 12:50:00 to 13:05:00

$start_time = 12:50:00;
$stop_time = 13:05:00;
$interval = 60;
$repeater = 2;

table ‘tasks’

id ¦ time ¦ code ¦ action ¦ status ¦ created ¦ lock
---------------------------------------------------------------------------------
3 ¦ 12:52:00 ¦ 303 ¦ action3.php ¦ idle ¦ 2004-01-17 12:45:00 ¦ false
2 ¦ 12:51:00 ¦ 202 ¦ action2.php ¦ idle ¦ 2004-01-17 12:45:00 ¦ false
1 ¦ 12:50:00 ¦ 303 ¦ action3.php ¦ done ¦ 2004-01-17 12:45:00 ¦ true

tasks
‘id=1’ $starttime (12:50:00)
‘id=2’ $starttime + $interval (60 seconds)
‘id=3’ last time (12:51:00) + $interval (60 seconds)

time now() + random(startID) + random(processID) + random(codeID) and output = table ‘display’

table ‘timer’
timerID ¦ start ¦ end
- - - - - - - - - - - - - - -
1 ¦ 12:50:00 ¦ 13:05:00

table ‘tasks’

table ‘display’
id ¦ time ¦ codeID ¦ command
-------------------------------------
1 ¦ 12:50:00 ¦ 303 ¦ action3.php
2 ¦ 12:50:05 ¦ 101 ¦ action1.php
3 ¦ 12:50:10 ¦ 303 ¦ action3.php