Sharing With Passion

September 08, 2012

Posted by Sabar Santoso in | September 08, 2012 No comments
















When you talk about viewing a PHP page, you are referring to a Web page. When you go to a Web page a series of events occur. These events start at the client with the request, go to a server to get the page, and end back at the client for viewing. Take a look at these events as listed below,

  1. The client computer connects to the Internet.
  2. The client opens a Web browser.
  3. The client requests a page from a Web site. When you do this, a message is sent over the Internet to a name server, and the name server then directs you to the server that hosts the Web page.
  4. The server that hosts the Web page receives your request and retrieves the requested page.
  5. If the page is a scripted page, such as a PHP page, the server compiles the page through a just-in-time compiler that generates HTML.
  6. The server then transmits the completed HTML back to the client (the browser).
  7. The Web browser receives the HTML and displays an interpretation of the page.
All of that is fairly straightforward; it’s almost like magic. There is only one catch—from browser to browser, your Web pages are not displayed identically. That is why we say the browser interprets the page. For instance, when Internet Explorer receives a page that includes nested tables, both with heights of 100%, Internet Explorer interprets the height
of the inner table relative to the height of the outer table. However, in Netscape Navigator, the browser will make both the inner and the outer table the height of the browser window. This poses a problem if you want a page to look the same in multiple browsers.

It gets worse when you switch between OS platforms. Let’s say you have a page of text, and for some reason the text determines the layout of the page, and you get it looking perfect on a Windows platform. When you then view the page on a Macintosh, the font is rendered very differently. The kerning (the space between characters) and the leading (the space between lines) is totally different. In fact, the font itself might be changed to a different font altogether. Style sheets can mitigate some of these problems, but you’ll still run into layout issues. The point is that what the browser displays is not a photograph, so if you want your games to work on several different browsers you have to be careful about the types of elements (text and graphics) you use.


The Web Server

Now that you have a general understanding of how a client/server relationship works you can take a closer look at the heart of the beast: the Web server itself. A Web server runs what is called an HTTP daemon. This daemon handles all of the requests received on a particular port. The HTTP daemon will listen to two ports—port 80 and port 443. Port 80 is the general Web port (http://). Port 443 is the standard for secure socket (https://). A Web server is also said to be stateless. That is to say, no permanent connection is maintained between the client and the server. This is extremely important to understand. It will make debugging or solving certain problems much easier, and, more important, this concept will completely change the way you design your games. It won’t be as easy as making a library of functions or a simple engine and calling functions. You will need to develop a way to keep state.

Think about that for a minute. What does that really mean? Well, it means that every time a particular event happens in your PHP game—e.g., the user enters coordinates and clicks the fire button—the Web browser will reopen the connection to the server, resend the request to the server, and the server will then process the page and send it back. Now you need to reload all of your variables/states and update the page appropriately. Otherwise the whole game would start over, and that would be no fun. Don’t get me wrong—there are some client-side scripting languages, such as JavaScript, that you can use for clientside event processing. However, that is beyond the scope of this book, which focuses on how to make games with PHP. So how exactly do you do this?

0 comments:

Post a Comment

Silahkan Isi Komentar Anda :

Search

Bookmark Us

Delicious Digg Facebook Favorites More Stumbleupon Twitter