PHP - How To Use Real Time Instead Of A Tick Based System
Hi, i am thinking of creating a text based game mmorpg using php/mysql etc... I know that a lot of these types of games use a tick based system, but i want it to be realtime, the only game i cna find that uses this is Torn, does anyone know how they make it realtime? I know that ticks can be controlled by cronjobs, but how about realtime?
The problem is that the game might involve the player building a house, in a tick based system it could be easy to manage by saying the house will take 3 ticks to complete, but i want the house to be like in 10 minutes of 32 minutes, how can i do this. Someone said to check whenever the player next logs in to check if the house has finished and then say it has been built, but seeing as it is an mmorpg it could affect everyones gameplay, not just the person building it, so this will not work. Thanks and sorry if this is a bit confusing. Similar TutorialsHi. How to implement twitter like real-time sharing system? So that is like, if my friend(following person) write a message, it also appear on my wall(page). 1. Is it hard? 2. What language used for it? PHP? 3. Is there any source about it? Thanks. Hello, I am building an online game(users make a character and move on a map and so on...)
All user data is stored in a mySQL database and I want the users to interact in real-time, but there can be a 1-3 second delay between the communication, but not exceed 3 seconds even if 500 players are playing at the same time.
But for the purpose of the question let's say the users can only chat between one another, if I'll have a solution for that then I can use the same method for more parts of the game.
I can't use websockets because my webhost doesn't support it( I don't want to use pusher.com).
I know I can make real-time apps with ajax long polling, but I think that with 500 players playing at the same time it's not the best solution.
So, finally:
How can I make user interaction as close as possible to a real-time game?
(Without too much load on the hosting server)
(I am sorry if some of my terms are not correct - I am just getting back to coding after a long time...)
Edited by Mythion, 17 August 2014 - 02:34 AM. Hi guys, got some questions about the Instagram real-time api. first let me tell you what I want to do. I'd like to run a daemon process with a socket connection or something of the like to the Instagram API to get a constant feed of photos with a certain tag. We estimate it to be a large amount of data at a particular time (thus why we want to go Real-time). This process will parse the feed and store it into a mongodb database. Secondly, for the front end, I'd like to display all new, live photos in real-time, possible with ajax or some form of checking on a set interval. Problem being, I can't find anyone doing this with php. All of the resources I have seen use Node.js and Tornado. Has anyone done this with PHP or know of a good Real-time API demonstration/tutorial to get me started? Here's the documentation... http://instagr.am/developer/realtime/ any help would be greatly appreciated! thanks! Ok so I have a question. is it possible to make a form submit to a DB in real time without the need for a submit button ? if so could you drop a hint to what it would be caled or a tut / reference to it ? PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel I wrote a short script that takes a list of keywords and does a Google search to find how often they are used in the title of a page. However, I cannot get it to echo the results in real time. On one server I use it works fine. On the other it runs the entire list and then outputs everything in the end. The problem is sometimes this takes several minutes and therefore it times out after not receiving a response. Any suggestions? Thanks in advance. <?php $file = file('words.txt'); $results = ''; foreach ($file as $line) { $data = file_get_contents("http://www.google.com/search?hl=en&q=allintitle%3A%22" . urlencode($line) . "%22&btnG=Google+Search"); preg_match('/of about <b>([0-9,]*)?<\/b>/si', $data, $number); $results .= $line . ";" . $number[1]; echo $results . "</br>"; $results = ""; sleep(2); } ?> I'm working on a chat using basic textarea input, post, but the problem that I'm facing is, if a person doesn't send something, then the output is not updated eg. other messages from other users updating in real time.
How is that achieved when you see new database entries pop up live, milliseconds after they are entered?
Do I set a constant refresh rate of some sort?
How do you update a section of a webpage without "refreshing" the entire page like the POST method?
I am having a problem with PHP displaying the correct date and time. It updates as it should, but is fast by 4min and is always displaying a date in 2004. I ran a basic php script to make sure the application im using itself is not wrong. go to lunenburgledger.com/time.php Anybody had any ideas on where to check? The system time on the Windows Server 2003 is correct. The only thing I can think of is that it was converted to a virtual machine on vmware esxi, but the system time stayed right. Any ideas? Thanks! I'm not looking for code, mostly just some direction, but I'm sure I'll be back as I try to shape the code. Also, I know very little about coding jQuery, Ajax, etc. Here is what I'm looking for: Basketball coach enters a Page that only he (or admin) can see. (I have that part figured out.) Once there, he has a form to fill out with a player's name and other information. I'd rather there not be 12 rows of empty cells. (Coaches will view that as work) I'd rather not have the Page reload on each "Add", but that would be the lesser of two evils. Is there a way to keep a persistent connection so when a coach hits Add, the player gets added to the database, a new empty form shows up, and the player's information shows up below on a roster? This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=322054.0 Basically I have recently been playing around with parsing a csv file. What I am looking to do at this point is simply take the date/timestamp (part of the csv file), which is in the following format:DD/MM HH:MM:SS.100th/s For the sake of argument, lets say I have this in an array string called $csv[0] and the file has several lines that span the course of a couple hours. I wouldn't mind having to use explode() to breakup/remove the date or 100th/s IF that would make things a lot simpler. So where would I start in trying to achieve this?. The result I am looking for will simply return "X Seconds". Storing this in a string variable would be a bonus, as I plan to use this to divide a separate piece of information. Any examples or ideas would be great. Thank you. ps: Here is an example time from the csv file itself: Code: [Select] 11/19 22:23:18.143 hi, i am working on a project in school ( web based application ) that requires me to do the whole reservation pannel as in the website. i am trying to do something close to www.expedia.com ( on the left ). any ideas how to do it. i have done my database in php my admin and i use dreamweaver to create my forms as i connected my database to dreamweaver. any help how to do it on dreamweaver without using codes ?? appreciate any help. Hi guys. I have a problem in my web based examanation system written in php. Here's the scenario: when a user takes an exam. 1 question is displayed 1 at a time. my problem is if he/she is at the 2nd question then he/she pressed the back button he/she is redirected back to the 1st question and my system just go crazy. How can i prevent the user from pressing the back button or returning to the previous questions? Please I really need help on this. Can anyone give me suggestion for possible solutions on my problem? Thanks in advance by the way here's my code, you can also download it from attachment. ------------------------------------------process_exam.php------------------------------------------------------------ <?php //start session session_start(); //declare variables //iCorrect= variable for score $_SESSION['iCorrect']=0; //a=variable for iteration kang index kang mga array or serves as an current item number $_SESSION['a']=1; //connect to database include('mysql_connect.php'); $result = mysql_query("select * from questions where exam_id ='$_SESSION[exam_id]'"); //count the number of found questions $_SESSION['num_of_questions']=mysql_num_rows($result); //declare the iterator $i=1; //get the options for the question1,question2 and so on and so on. depende kung ilang questions ang mafetch nya sa dbase.so pde kht ilang questions lagay ng user while ($row = mysql_fetch_assoc($result)) { $questions[$i] = $row['question']; $op1[$i] = $row['op1']; $op2[$i] = $row['op2']; $op3[$i] = $row['op3']; $op4[$i] = $row['op4']; $answers[$i]=$row['answer']; $i++; } //view the data's in the array for debugging purposes echo 'answers: '; print_r($questions); echo '<br>'; print_r($op1); echo '<br>'; print_r($op2); echo '<br>'; print_r($op3); echo '<br>'; print_r($op4); echo '<br>'; print_r($answers); echo '<br>'; echo '<br>'; //pass the arrays to session arrays to be used in other php pages $_SESSION['question']=$questions; $_SESSION['op1']=$op1; $_SESSION['op2']=$op2; $_SESSION['op3']=$op3; $_SESSION['op4']=$op4; $_SESSION['answers']=$answers; //print the arrays. debugging purposes //1 is the starting index of the array because the $i is equal to 1 print_r($_SESSION['question']); echo '<br>'; print_r($_SESSION['op1']); echo '<br>'; print_r($_SESSION['op2']); echo '<br>'; print_r($_SESSION['op3']); echo '<br>'; print_r($_SESSION['op4']); echo '<br>'; print_r($_SESSION['answers']); header("location:exam.php"); ?> </body> </html> ----------------------------------------------------------exam.php-------------------------------------------------------------------- <?php //start session session_start(); echo '<br>'; echo '<br>'; echo '<tr>'; echo '<b>'; echo 'Question: '; echo '<td align = center>'.$_SESSION['question'][$_SESSION['a']].'</td>'; echo '</tr>'; echo '<form method = "post" action= "nxt_question.php">'; echo '<table border = "0">'; echo '<tr>'; //echo '<td>'; echo "<td><Input type =\"Radio\" Name =\"choice\" value='".$_SESSION['op1'][$_SESSION['a']]."'>"; echo '<td>'.$_SESSION['op1'][$_SESSION['a']].'</td>'; echo '</tr>'; echo '<tr>'; echo "<td><Input type =\"Radio\" Name =\"choice\" value='".$_SESSION['op2'][$_SESSION['a']]."'>"; echo '<td>'.$_SESSION['op2'][$_SESSION['a']].'</td>'; echo '</td>'; echo '</tr>'; echo "<td><Input type =\"Radio\" Name =\"choice\" value='".$_SESSION['op3'][$_SESSION['a']]."'>"; echo '<td>'.$_SESSION['op3'][$_SESSION['a']].'</td>'; echo '</tr>'; echo "<td><Input type =\"Radio\" Name =\"choice\" value='".$_SESSION['op4'][$_SESSION['a']]."'>"; echo '<td>'.$_SESSION['op4'][$_SESSION['a']].'</td>'; echo '</tr>'; echo '</table>'; echo '<tr> <td> <input type = "submit" value="Next Question"> </td> </tr>'; echo '</form>'; ?> ----------------------------------------------nxt_question.php------------------------------------- <?php //start session session_start(); //Checking of answers kada mag pindot next question button if(isset($_POST['choice'])) { $ans_of_user=$_POST['choice']; $_SESSION['answers'][$_SESSION['a']]; if (strcmp($ans_of_user,$_SESSION['answers'][$_SESSION['a']])==0) { $_SESSION["iCorrect"]++; } } //add 1 to the session a. session a is the iterator. serves as indexes of the arrays that stores the questions,answers etc... $_SESSION['a']++; //ridirect to exam.php if there are still number of items remaining. while($_SESSION['a']<=$_SESSION['num_of_questions']) { header("location:exam.php"); exit(); //kill the script } echo 'exam finished!'; echo '<br>'; echo 'Your score is: '; echo $_SESSION["iCorrect"]; //unset the session variables needed to be reset unset($_SESSION["iCorrect"]); unset($_SESSION["exam_id"]); unset($_SESSION["invitation_code"]); unset($_SESSION["a"]); unset($_SESSION["num_of_questions"]); unset($_SESSION["question"]); unset($_SESSION["op1"]); unset($_SESSION["op2"]); unset($_SESSION["op3"]); unset($_SESSION["op4"]); unset($_SESSION["answers"]); ?> This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358615.0 hello dear php-experts i run opensuse 13-2 and i am very very happy the time does not get displayed correct. it falls back to UTC all day. What can i do. i have had look at the documents here https://en.opensuse....uring_the_clock https://tr.opensuse....T_Date_and_Time how to set up correct to the local time - note i live in GERMANY near francfurt Hello Guys, I would really appreciate some feedback on this one. Here's the basic simplified code for my bidding system site (querys for when a user sends a new valid bid): Its working fine but if 2 users send a bid at exactly the same precise moment (even same milliseconds), I have 2 problems (described below code, for better understanding) Please picture this code as if its happening 2 times at the same time (from 2 different users) Code: [Select] $time = microtime(true) * 10000; $result = mysql_query("UPDATE `AUCTIONS` SET Current_Price = Current_Price + '$increase_price', Bids = Bids + 1, Bidder = '$bidder', Bidder_Time = '$bidder_time' WHERE PId = '$id'"); //grab the current price to save on bidding history DB if($result) { $resultPrice = mysql_query("SELECT Current_Price FROM AUCTIONS WHERE PId = '$id'"); while($row=mysql_fetch_array($resultPrice)) { $current_price = $row['Current_Price']; } if($resultPrice) { $result = mysql_query("INSERT INTO `BIDDING_HISTORY_DB` (Id, Bidder, Bidder_Time, Raw_Time, Ip, Type, Bid_Amount) VALUES ('$id', '$last_bidder', '$last_bidder_time', '$time', '$client_ip', '$credit_type', '$current_price')"); } } If 2 users bid at exactly the same SAME moment, its possible that on BIDDING_HISTORY_DB... I get the Bid_Amount field with the same value (when it should be always 1 number higher than the previous) ( Bid_Amount is coming from $current_price) $current_price grabs the new updated value from the AUCTIONS DB on the first query (Current_Price = Current_Price + '$increase_price'). So its impossible to have 2 values that are the same (at least I am not expecting that), but I realized that if the query from 2 users are being processed at the same time and the UPDATE AUCTIONS query is processed 2 times and AFTER THAT then the SELECT Current_Price FROM AUCTIONS WHERE PId = '$id' is processed on both bids...that is when the Current_Price is grabbed with the same value for both USERS!! Any ideas on how I can find a solution to this ??? The other problem is that I am knowing which bid was made (by which user) before/after because of the $time variable. But sometimes when 2 bids are made at the SAME precise time with the same milliseconds (yes it happens) ... this is when problems arise (because 1 user could have as Current_Price 10.11 and the other one 10.12 and then on DB the user with 10.12 could be shown as if he made the bid first, any ideas/suggestions on how I can find a solution to this? Hi peps, I am trying to write a script that allows for events to be executed at any given time that user gives it like if the user wants it at 2 am the event will execute at that given time i read some answer they say use cron but im using windows how to do it ?? Hello everyone, here is my problem. I am working for someone that would like users to be able to create a Trial Account on their website. This trial account is to be used for 24 hours, once the 24 hours is completed they can no longer login/use that account. Everything about the Trial Account is completed, other then the account timer. I am at a loss on how to get this part done. I was thinking that I would use the MySQL commands, GETDATE() and DATEADD(), to get the date and time that the account was created and using the DATEADD() command I would add 24 hours to the GETDATE() value. Then if the user logs into at a date past the DATEADD() value the Users Account type is switched to 3(This means that the account has been disabled) and then is directed to the Logout page, which then redirects him back to the homepage. After this point, the user can no longer login due to the code preventing any user with an account type of 3 to login. The problem is that I am unaware how to incorporate the GETDATE() and DATEADD() functions into my PHP code. Would anyone be able to explain how I can get this done, or suggest a better method of inputting a starting time and ending time for the account? Thank You for any/all help. Hi everyone... I would like to implement a questionnaire/survey system that has only two Answers (Yes /No). Basically, this questionnaire system will be widely used on Mobile Phones. It will be looking something like this below: http://awardwinningfjords.com/2009/06/16/iphone-style-checkboxes.html Lets say a user selects a response as No (Using the above slider button for a question). That response should be recorded in the database with User Details + Time Stamp. Also, I would like to generate a report for each question (Responses of Multiple Users) and a report at a User Level for the entire questionnaire/survey (s). Can some one guide me the fastest & easiest way to achieve this? I'm a new learner of PHP. Regards Sandeep I created a "statistics of site" page, stats.php. Currently stats.php updates every visit, that's over 25 queries for every visit, with over 9,000 visits a day, I wish to cut down. What is the best way to make it so all queries are done every hour, therefore requiring less queries to the database? I assume the best way to go at this would be either to run a time() based script every 60 minutes and: - update this to a new field, then stats.php will require 1 query every visit, plus the 1 every hour. or - update a text file and read that each stats.php visit, meaning just the 1 query every hour. Now, I understand the second option will run much less queries overall, but is it the best way to go? Is there a better way to go about doing this? |