What I think I want:
A language that would run persistently on a server to run recurring events that would be able to respond to html requests and give them tailored data. The scheduled events would be dynamically timed and occur frequently. The events would almost always be changes开发者_如何学JAVA to database information, and the results would be viewed through a web application.
Why I think PHP isn't going to work for me:
Since I can only get my PHP to run when a user requests a page, or through a fixed rigid schedule, I'm having to look at the request time versus the last time it ran and fill in the gaps that should have happened. For example, if I had something that needed to occur every 15 minutes and no PHP scripts ran for several hours; then it would have to check how many were missed a run catch up to simulate what I believe should have happened in that time.
Real world examples and specifics:
I'm going to point to a really stupid example in this section because it's actually really pretty close in real-world concept to what I'm trying to explain. The online game neopets has shops that restock every so often with randomly generated goods. It restocks more if the store is emptier during every ~15 minute restock but the old items remain.
This isn't what I want exactly, but I recognized that at it's basic concept was extremely similar. I'll be extrapolating some odd additions to this system as I think it makes more sense than what I'm actually doing.
What should I do to recreate this shop but with the following requirements:
- Restock times are dynamically derived from other events occurring (set time since another item sells perhaps), therefore the schedule isn't a rigid "every quarter hour" that I can run through scheduled PHP scripts. Instead it could be exactly at 5:46:23PM
- The "restocking" is derived from other time specific information. I am unable to just simulate all restocks that should have occurred once a new customer checks the page.
What direction should I go?
I have no idea what I'm talking about so assume the following is shit:
I suspect I am wanting a persistent running program on the server that performs these tasks and puts the results into a database which is then accessed and delivered through php to the end user. I'm really just getting started though and I know I'm very likely making a very stupid assumption. Is there something that is both the persistent program and PHP together that I should learn?
I'm doing this as a hobby and just want to learn more so I can make more fun toys for myself.
I think you are mixing up two concerns:
A language that would run persistently on a server to run recurring events that would be able to respond to html requests and give them tailored data
You are not looking for a language to run persistently, but for a system, e.g. a JobQueue (something like Gearman). This JobQueue will do your main scheduled works. You can use PHP to get messages from that queue, trigger new jobs and inspect running jobs, etc. in addition to building the website people will interact with in PHP.
You could always use CRON and call a PHP file to do the dirty work, for the logic side. (And by that I mean, use the PHP "system" function Documented Here to do the rescheduling commands in CRON itself)
精彩评论