- Web browsers are clients. Web servers are servers.
- PHP executes on the server.
- A mix of server-side and client-side technologies make “Web 2.0” possible.
- You can help make the web better by making sure you have a good browser.
In conversation with a friend of mine, I realized that he lacked a firm grasp of the client/server relationship between web browsers, also known as “user agents,” and web servers. The following has been written for him, but I decided to post it here because I believe it may be of interest to others.
First, let your author define a client/server relationship. While there are many different systems in the world that use a client/server relationship, we’ll be considering it solely from the perspective of the web. A server is a computer system that makes resources available to other systems upon receiving a request. A client sends requests to the server, receives replies, and then is able to act on the information it receives.
In the case of the web, the server holds a variety of resources. Typically these are web pages. An individual web page is actually composed of several files: a document, images, videos, stylesheets, and server-side and client-side scripts. The server assembles all of this into a coherent package of data and then transfer it over to the client, typically a web browser, which displays it the user.
The language the server and the client speak to each other is called HyperText Transport Protocol, HTTP for short. HTTP is a stateless protocol. That means the browser sends a request, the server replies, and then the server closes the connection and completely forgets about the browser. Each exchange is an isolated transaction with no context from previous exchanges.
Along the way, those who designed solutions on the web realized that there was sometimes a very real need for state. Thus a few different solutions, including browser cookies and PHP sessions, were invented to graft state on top of the stateless nature of HTTP. Into all of this come the server-side and client-side scripting technologies which create and rely on that state.
Server-side scripts are executed by the server and modify its response to the client upon receiving a request. They allow developers to create dynamic content (web pages that change based on the information sent by the user).
Server-side scripts offer the advantage of security and integration with server-side resources. Because the scripts run on the server, a malicious user can’t simply fake an outcome and send data back to the server to trick it. The server-side scripts can also record information into the server’s database or into a file to store long-term information for the user. Also since the user only sees the output of the server-side script, proprietary code and technology aren’t exposed to clients who could simply copy them or derive their own sites from them.
The downsides of server-side scripts is that they pose a “scalability” challenge because as the server receives more requests, it must tie up more resources processing the server-side scripts and creating dynamic pages to then send over to the browsers. This must all be done quickly because the browser, and therefore user, sit and wait until the scripts complete on the server. If load becomes too high, the server may slow down unacceptably or scripts may even fail to complete successfully. At that point, the server owner must either find significant performance gains in refactoring the scripts or upgrade the server.
Client-side scripting is essentially the opposite. Since all the execution happens in the user’s browser, CPU and memory resources are readily available and a slow down on one user’s browser won’t affect any other clients accessing the server. Because browsers have typically been single-threaded, it’s possible to create scripts that are too intensive and appear to make the browser “hang” while they execute. This will change as the new HTML5 Web Workers technology becomes available on more computers, through users upgrading to more recent browser versions.
One final note: if you haven’t upgraded your browser in a while, get a better browser. Many web developers are pressured to support old browsers with limited features. As you, the user, adopts newer browsers, we can build better applications, and we can build them faster and more easily. The outcome is a better web for all of us. I’d strongly recommend you try the latest version of Google Chrome.