LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-22-2017, 05:18 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
Question Need confirmation/suggestions on linux scripting


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.
 
Old 05-22-2017, 05:45 PM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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).
 
2 members found this post helpful.
Old 05-22-2017, 05:57 PM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,222

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Sounds like you might want to look into websockets.
 
1 members found this post helpful.
Old 05-22-2017, 06:13 PM   #4
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by hydrurga View Post
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.

I'll look into web sockets!

Last edited by wh33t; 05-22-2017 at 06:18 PM.
 
1 members found this post helpful.
Old 05-22-2017, 08:55 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
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.
 
1 members found this post helpful.
Old 05-22-2017, 09:10 PM   #6
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by Turbocapitalist View Post
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.
 
Old 05-22-2017, 09:28 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ash Scripting Suggestions: Copy multiple directories into one? Trako Programming 1 03-14-2014 05:08 PM
Subject: : Confirmation of the initial creation date of directories in Linux environ Munawar Shah Linux - Newbie 2 02-04-2012 05:47 AM
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
Scripting suggestions Greek Acrobat Programming 11 06-28-2004 08:28 AM
vnc on linux: enable connection confirmation.... pablovschby Linux - Networking 4 12-23-2003 05:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration