Home Community Mys-Script Creative Off-Topic |
|
|
Thread Tools | Display Modes |
#11
|
||||
|
||||
How would I do scheduled tasks? I don't know how to make a script run whenever someone just visits the site, unless it goes in index.php or something.
__________________
|
#12
|
||||
|
||||
First of all, you need to create a database table called adopts_tasks(assuming your database prefix is adopts_, change to whatever it is if not). This table should contain some useful data field such as task id, name, description, action to execute, last execution time, next execution time, time interval between each execution, etc.
Second, create a script file for each of your tasks, and find a way to link it to the data field 'action to execute' in your new database table(ie. mooddrop.php). A simple way is to just use include/require and the file being a procedural file. Or even better, write Task classes that will make it easier to inherit some parent properties/variables. Mysidia Adoptables v1.4.0 will use the latter approach, but if you just barely get a hang of programming the former procedural approach may be more feasible. Next, add some code to index.php file, this way this code always runs whenever someone visits your site, even a search bot. The code will need to pull all the scheduled tasks ready to run from your new database table(current time is greater than or equal to the next execution time), and execute the script file each task links to. After the script is executed, increment the next execution time by the wait time, and update your database table so the tasks will not run again until it should. For instance, if you have a scheduled task linking to file mooddrop.php, its next execution time is today at 8am and wait time is 3 hours. When you visit your site at 9am, it will load the scheduled task from database, execute the script inside mooddrop.php, and update the next execution time from 8am to 11am(3 hours interval). Then the task will not run again until someone visits your site again after 11am. Now you see, it is a simple trick that will work well given you have an active site with visitors at least once per 3-5 minutes. If you are on a virtual machine/devbox, it will not function properly since you are the sole visitor. In fact, this is exactly how our forum software's scheduled task system works. It uses pseudo-cronjobs, and you dont have to manually set up all cronjobs from cpanel. Of course, you may face some challenges such as how to write task files/classes, how to compare date, and how to store data values in database. Lemme know if you have any questions, I will try to explain and help you with this.
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#13
|
||||
|
||||
Finally on break so I can work on this. Would this be the correct setup for the table?
This is also what I have so far for my lowermood.php: PHP Code:
__________________
|
#14
|
|||
|
|||
While i was trying it i got error
Fatal error: Uncaught exception 'Exception' with message 'Database error 1054 - Unknown column 'aid' in 'field list'' in /home/dacankey/public_html/classes/class_database.php:213 Stack trace: #0 /home/dacankey/public_html/classes/class_database.php(142): Database->_query('owned_adoptable...', Array, 'select', '1 ORDER BY RAND...') #1 /home/dacankey/public_html/view/indexview.php(10): Database->select('owned_adoptable...', Array, '1 ORDER BY RAND...') #2 /home/dacankey/public_html/classes/class_frontcontroller.php(100): IndexView->index() #3 /home/dacankey/public_html/index.php(74): FrontController->render() #4 /home/dacankey/public_html/index.php(78): IndexController::main() #5 {main} thrown in /home/dacankey/public_html/classes/class_database.php on line 213 |
#15
|
||||
|
||||
What does your code look like?
__________________
|
#16
|
|||
|
|||
which code
|
#17
|
||||
|
||||
The one that's giving you the error.
__________________
|
#18
|
|||
|
|||
Can you show me your owned adopt table phpmyadmin screenshot of structure
|
#19
|
||||
|
||||
__________________
|
#20
|
|||
|
|||
I think its other problem which hall of fame can solve :( and merry christmas
|
|
|
What's New? |
What's Hot? |
What's Popular? |