Subscribe to andrewsw's Blog        RSS Feed

Client and Server, briefly

Icon 4 Comments
The following is an attempt to explain in simple terms the difference between client and server-side processing. Specifically, the difference between Javascript, which runs on the client, and PHP (and other server-side) languages which, of course, run on the server.

The client is your computer. When you click a link on a web page, your browser prepares and sends a request to a server. There are different types of request, and different information that can be sent with the request. For a simple web-page link the request is for an HTML-document.

The client can either be considered as your computer, or your browser. Technically, it is your computer. But as the browser prepares and sends the request, and processes the response, the distinction is not important.

The server responds to your request. It prepares, and eventually returns, the HTML-document. If the document contains only HTML then the document will simply be returned, along with related files: CSS, Javascript, images, etc.

The process is slightly more complicated than this. For example, if the page was requested before, then the CSS-files, etc., may already be in the browser's cache. But let's continue..

Even if the HTML-document includes embedded CSS rules, or Javascript code, this is irrelevant to the server. To the server, all of this content is, essentially, plain text, and will be sent back as is.

If the requested page includes server-side code, such as PHP, then the PHP interpreter on the server will execute this code. The PHP interpreter runs entirely on the server. Once it has completed its work (has executed the PHP code) it is no longer involved in the request.

The job of the server-side code is (mainly) to add additional content to the page: more HTML, CSS, etc.. It can also add Javascript code to the page. PHP (and other server-side languages) DO NOT UNDERSTAND Javascript. Again, as far as the server-side language is concerned, this Javascript is just plain text that it is writing to the page.

As part of its job, the server-side language can also communicate with a database on the server, or manipulate text or XML files. It can even build images or pdfs.

The server completes its work by returning the completed page (and associated files) to the client - your computer. The server continues with its main job: listening for, and responding to, requests. It doesn't know, or care, what the client does with the response it has just sent.

The client receives the response from the server. The browser has a number of tools to help it process the response: HTML parser, CSS parser, Javascript interpreter. The only code that the browser understands, and can execute, is Javascript.

There are other technologies that a browser can understand, such as Java Applets or Flash. These, however, require plug-ins to be installed on the client-computer. Javascript is the only language that every browser can interpret.


This is obviously a very simple (perhaps simplistic) description of the differences between client and server-side processing. The main points I am trying to convey are:

  • Javascript runs on the client.
  • PHP (and other server-side languages) don't speak Javascript.

Note Someone clever might point out that node.js does speak Javascript, but that is just a distraction from the main point I am making.

Posted Image

wikipedia said:

How clients and servers communicate

Clients and servers exchange messages in a request-response messaging pattern: The client sends a request, and the server returns a response. This exchange of messages is an example of inter-process communication. To communicate, the computers must have a common language, and they must follow rules so that both the client and the server know what to expect. The language and rules of communication are defined in a communications protocol.

Client-Server Model :wikipedia

Request-response :wikipedia

Hypertext Transfer Protocol :wikipedia

wikipedia said:

HTTP functions as a request-response protocol in the client-server computing model. A web browser, for example, may be the client and an application running on a computer hosting a web site may be the server. The client submits an HTTP request message to the server. The server, which provides resources such as HTML files and other content, or performs other functions on behalf of the client, returns a response message to the client. The response contains completion status information about the request and may also contain requested content in its message body.

4 Comments On This Entry

Page 1 of 1


11 December 2013 - 12:55 PM
Shoot you beat me to it. (I was going to make a NodeJS comment.)


11 December 2013 - 12:57 PM
There is though PECL V8js and MongoDB::execute to do some JS from within PHP.


11 December 2013 - 01:54 PM
Thanks @snoj, but let's hope that those links do not distract the reader from my primary purpose, which is to provide a simple explanation.


18 December 2013 - 12:01 PM

snoj, on 11 December 2013 - 08:55 PM, said:

(I was going to make a NodeJS comment.)

Still, the Node.js script treats the Client-side JS as simple text. mostly because there is a strong differentiation between server-side code and client-side code (or in other words, in Node.js you hardly work without a templating engine).
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

October 2020

2526272829 30 31


    Recent Entries

    Recent Comments

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)