Skip to content

Instantly share code, notes, and snippets.

@mikedamage
Created December 29, 2011 02:55
Show Gist options
  • Save mikedamage/1531412 to your computer and use it in GitHub Desktop.
Save mikedamage/1531412 to your computer and use it in GitHub Desktop.
PHP Project Idea for Mike

PHP/MySQL Project Spec

Summary

Design and develop a PHP and MySQL based script that concatenates text files based on query string input, then caches the resulting concatenation in a database table.

Functionality

The script should work like this:

Assume you have a folder that has the following structure:

  • css
    • screen.css
    • print.css
    • ie.css
  • js
    • application.js
    • jquery.js
    • spoons.js
    • forks.js
  • combine.php <--- this is the PHP script

When someone visits the URL 

http://localhost/combine.php?files[]=js/application.js&files[]=http://code.jquery.com/jquery-latest.js&files[]=js/forks.js

The script should iterate through the array provided in $_GET['files'], get the contents of each file using file_get_contents(), and add them to a string variable. It should then store the string in a MySQL database as a TEXT field, and the file names concatenated together in a VARCHAR(255) field for querying later; it should also record an auto incrementing ID field as primary key. Finally, the script should return the concatenated text to the browser via echo or print. When the user requests the exact same files, the script should return the cached result instead of concatenating them again.

Kinda hard to give an example of a DB table in a text file. If you need to see one, let me know.

Misc.

Let me know if you need any other details. This project should probably only take you like 2 days to build, and that's mostly research. Knowing what I already know about PHP, I could probably make something like this happen in 2 hours or so. The most confusing part is the behavior, but the code will be really simple. 

Start with just combining and returning the script files. Once that works, start storing the result in the DB. Once everything else works, figure out how to cache and check whether a particular combo of files already exists in the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment