views:

89

answers:

3

Hello
I new in php and i interested at games like a poker.
I think when started new game,there must be created new thread. But I read that php does not support multithreading.
Can you advise what i must to do for support multithreading .

Thank`s

+2  A: 

You don't need multithreading to write a game, especially not one like Poker which operates in distinct sequential steps.

Start small and worry about advanced topics like multithreading once you have worked out how to write a basic poker game.

Jason Williams
A: 

Multithreading is only useful for splitting tasks in one single instance of a game or whatever php app into separated threads. Depending on your server's configuration a new apache / php thread is started whenever one starts the game. You don't have to implement this by yourself - every user get's his own script instance automatically.

For writing your own browser game you won't have to implement multithreading as long as the calculations won't get too time expensive.

As Jason already stated, just start small and worry about advanced topics later.

dhh
A: 

seems you did not understand what php is all about: php is a server side scripting language that will (in general) perform some server side actions and produce some (textual) output which is then sent back to the client - usually an html file.

thing is - the php script starts running once the webserver receives the POST or GET message from the client. when the response is sent to the client, the script stops. yes: it dies!

so there is no sense in opening a thread or so if a new game is started - since this thread (if threading would be possible in php) would die with the script.

the approach of keeping "persistent" data (if that is what you meant with threading) is somehow different with php/html/...: you start "sessions", where each client has a unique session assigned. sessions will store variables for your users and can be "repeated" after the php-script starts again...

try searching for

session_start();

and the php global

$_SESSION
xenonite