#1
|
||||
|
||||
Using cronjobs
I thought this might be helpful for people who want some automatic functions on their site. Special thanks to Kyttias and IntoRain!
Disclaimer: It is not recommended that you have several cronjobs running at once unless you have a really good server, because it can potentially slow things down; especially if the runtime is frequent (IE: running several times a day) -Introduction- Create a new file in public_html (or wherever you have mysidia installed) called cron.php. Inside, paste this: PHP Code:
More often then not, you're going to want to do some math. Whether it's giving pets realtime needs or some sort of daily rewards system, the database needs to know how to math. Go to class_database.php and add this: Pastebin Link Here are the examples IntoRain gave on how these can now be used in scripts: PHP Code:
From here, it's just like coding for any other part of the script. Go to cron.php and create a new function like this (do not add anything to the index function or construct function!): PHP Code:
PHP Code:
Adding little notes right inside the functions is something I recommend so you can easily tell when it should run at a glance. They're also helpful if you have multiple coders, so notes are good! -Making it go- Now that you created your function, you need to run it. You might have noticed that cron.php has no coding on actually running the functions, and that's intentional! Many server hosts (including mysidia host) have CPanel available. Access it and navigate to cronjobs under the "advanced" section. (cpanel) (retro cpanel) (mysidiahost client area) Luckily for us, the page is full of presets. Clicking on the dropdowns allows you to specify exactly when you want the cronjob to run (even down to an exact minute once a year!) Customize it however you want. Afterwards use this for the command section: Code:
curl http://YOURSITE.com/cron/FUNCTION Code:
curl http://adopttest.mysidiahost.com/cron/changeSeason
__________________
|
#2
|
||||
|
||||
This is pretty handy, thanks :D
__________________
It's been a long time. I had so much fun making a site back in 2016 that recently, when I started thinking about it again, I decided to come back and work on something small. It'll probably just be a personal project but who knows? We'll see, anyway.
|
#3
|
||||
|
||||
This is fantastic, I was struggling earlier trying to figure this out! Thank you for sharing this
Edit; I am super tired and therefore lazy...so I'll ask you about this! So I am trying to run a cronjob that will allow me to lower all pets' Mood by 10 each day...if a pet's mood is already at 0, I do not want it to go below 0, so if it's already 0 then it will simply remain at 0. Any idea how'd you go about doing that?
__________________
My Mods Site (1.3.4, 2020 Mods) Last edited by Abronsyth; 06-30-2017 at 09:39 PM. |
#4
|
||||
|
||||
Hmmm, I think that could work if you use both a cronjob and myadopts.php. With the cronjob you lower mood by 10 daily, then on myadoptview (or myadopts) you can check the amount whenever a user manages their pet. So if the pet's mood is below zero, it sets it to zero. Though I suppose that wouldn't work to well if the user decides to use an item on their pet without checking up on them.
Maybe you could use this somehow? PHP Code:
It's late for me too, so I'll have to look at this more when I'm not tired lol.
__________________
|
#5
|
||||
|
||||
Quote:
PHP Code:
Last edited by KatFennec; 07-02-2017 at 02:45 PM. |
#6
|
||||
|
||||
I'll try that out and let you know how it works!
__________________
My Mods Site (1.3.4, 2020 Mods) |
#7
|
||||
|
||||
Nice tutorial, it will help a lot of users. We plan to implement a pseudo-cronjob system for next major release, but of course real cronjob will always work better.
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#8
|
||||
|
||||
Just letting you know that this works perfectly, thank you!
__________________
My Mods Site (1.3.4, 2020 Mods) |
|
|
What's New? |
What's Hot? |
What's Popular? |