ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm writing a web based card game that uses a combination of PHP and JS.
I need to write some kind of AI-bot that can fill a spot at the game. I'd like to keep all my backend code in PHP, but to my knowledge there is no way to make a PHP script run as a program/service (correct me if I'm wrong here).
So is it possible, and would it be a good idea, to write some kind of shell script that is constantly running that checks the database to see when it's the bot's turn to play a hand, and then run the appropriate PHP script?
Any pointers to any guides on the web that start me in this direction is greatly appreciated.
Server OS is Ubuntu-server and I'd like to stick with that. PHP is PHP7.
I may not understand the question, but I don't understand why you would need to have a constantly running script to act as the AI player.
Whenever it is the AI player's turn (i.e. on the online player playing their card or indicating that the AI player should go first), your JS/HTML code would call a php script on the server that would, after consulting the database, play the AI player's card(s).
I may not understand the question, but I don't understand why you would need to have a constantly running script to act as the AI player.
Whenever it is the AI player's turn (i.e. on the online player playing their card or indicating that the AI player should go first), your JS/HTML code would call a php script on the server that would, after consulting the database, play the AI player's card(s).
I don't want to give any kind of control to the client (beyond what they need). Also, if the player AFK's or DC's from the game the AI turn might never trigger, in which case some kind of server side check needs to run which I feel just gives me more reason to manage it from the server side.
If a file is created or modified when the player's turn is committed, then you might use incron / inotify to launch the PHP scripts. incron handles launching scripts when file system events are encountered, like when a file is closed. Specifically, incrontab is used to make the list of conditions.
If a file is created or modified when the player's turn is committed, then you might use incron / inotify to launch the PHP scripts. incron handles launching scripts when file system events are encountered, like when a file is closed. Specifically, incrontab is used to make the list of conditions.
No file is modified, unless you count a mysql table. I think I'm going to try out websockets. It seems like that's where the web is heading for this kind of thing.
No the table would not be updated to disk in a timely manner I suspect. You might trigger a script from MySQL / MariaDB using UDF. However, I have not used it myself to say what the weaknesses are and what little I see does look a bit dangerous.
If web sockets can be used with HTML5 and without requiring client-side, then it might be of good use.
Otherwise, I am guessing you have a form and submitting the form triggers a server side script. That script could write a file and trigger inotify for you. Or it could trigger the "AI" script directely.
Write a little more about the interaction and you'll get better guesses from us.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.