Advanced PHP Practice Interview Questions And Answers Part 3
This is the last portion of our PHP practice interview questions and answers. Here is part 3 of the PHP practice interview question:
Given the previous two portions of this question, can you name some of the drawbacks or disadvantages of the solution you provided?
And, here are parts 1 and 2 of the original question for your convenience:
Write a PHP script to report the total download size of any URL. You may not use any 3rd-party code that performs the entire task described below.
No HTML interface is necessary for this exercise; you can write this as a command-line
script that accepts the URL as an argument.
For a single-file resource such as an image or SWF, the script would
simply report on the total size of the document.
For a complex resource such as an HTML document, the script would need
to parse it to find references to embedded, included resources:
The goal of this exercise is to output the following information for a given URL:
– total number of HTTP requests
– total download size for all requests
The code should also be able to handle the URL in the src attribute of an iframe.
There are a lot of potential problems with the solution that we gave for this interview question. And, some of those problems are unavoidable given that this is an interview question, and you don’t have a few weeks to give a perfect answer. Try to see if you can think of any potential problems on your own.
Checking for duplicate resources
Checking for resources inside CSS documents
Another thing that we did not do is check for resources named inside external CSS documents – like “background-image”. That means our implementation will not count those resources, which would lead to a total number of HTTP requests that is lower than the actual number.
Checking for browser specific code
Another thing we did not do in our implementation is check for browser specific code – as in the HTML tags that look like this: “<!–[if IE]>”. This could also potentially affect the HTTP request count and total download size that our implementation reports, because certain files could conditionally be included depending on what browser the user is using. A common usage of this is to use a different stylesheet for older Internet Explorer browsers. This would mean that our implementation would double count – both the stylesheet for Internet Explorer and the stylesheet for non-Internet Explorer browsers.
One thing that may be challenging is accounting for the resources which are already cached by the browser. If a resource is cached, then it means that the browser will not generate a new HTTP request for that resource because the browser will just use the version of the resource that it has saved in it’s cache. This means that since we are not even taking browser caching into account in our implementation (something that would probably be very difficult), in situations where cached resources are used we would definitely be over-estimating the number of HTTP requests because we just count every single resource in the HTML as an HTTP request.
Final thoughts on Advanced PHP interview question and answer part 3
Now, those are just some of the potential drawbacks of our answer to the PHP interview question. Remember, you can see the final solution we came up with right here: PHP Interview Question Part 2. Writing something that is very accurate given all the complexities would be very challenging and time consuming – and would certainly not be expected in a PHP interview question like this. Most likely, what interviewers are looking for with a question like this is that you have some essential PHP skills, and a good foundation of knowledge for how the web works.