PHP CookBook: (YouTube clone)

With the increased popularity of the service many people wanted to organize a similar service, but don’t know how to do this. If you are one of them – this article is for you


First of all describe the basic site’s functions (and also determine and the role of users) :

  1. Guest
    • View video online
  2. Member
    • Upload videos
  3. Administrator
    • Manage users
    • Manage files

WEB 2.0 Features

We need to extend base functions, because we need to get more traffic:

  1. Guest
    • view comments on video
    • search for files (using categories or tags)
  2. Member
    • comment on videos
    • record video from Web (using webcam)
    • assign category to video
    • assign tag to video
    • rate video
    • organize list of friends
    • manage favorites
    • send in-mails
  3. Administrator
    • Manage comments
    • Manage categories

These are certainly not all the features of YouTube, but at least something to start with

Server Configuration

Our system will be based on LAMP:

  • Linux
  • Apache (version 2.2 and higher)
  • MySQL (version 5.0 and higher)
  • PHP (version 5.2 and higher)


And now describe the problems that you may encounter

Video Conversion

To gain user attention we need to allow them uploading videos in any format, but it’s more comfortable to users to get videos in one specific format (this will allow not to have a codecs-zoo on your machine and on the other hand if site requires some extra actions from user – it is very likely that user will forget your site – you know we are lazy. And what can be done with this? The answer is obvious – convert video files into a single format, and the format should be FLV. Flash-video can be viewed on most operating systems because it uses the widespread Adobe Flash Player software preinstalled on most browsers, and this format is also supported by many programs for video playback, such as MS MPlayer and almost all other players.

We need the following software tools (all opensource):

  1. mencoder or FFmpeg
  2. flvtool2 (need Ruby)
  3. PHP Program Package (‘example.php’ contains example using mencoder) or ffmpeg class (‘ffmpeg.example1.php’ uses ffmpeg)

You can use mplayer to get additional information about original video file.

If we properly assembled and installed, we can now convert…


People did not like to sit and wait while the file is silently downloaded to a server, the users are curious, so we would have to show progress bar:

All references are from xajax forum


ТIf we will use the same server for website and video conversion then website will be more dead than alive. For this purpose we will have to use another (one at least) server that will take original files from the web and put it back converted in a while. In other words we need more than 1 server to create a working solution.

Load distribution

If we store all data in one server, it will not carry the load. We must have several servers to store data :

  • etc

You must decide themselves how to distribute the load. You have to estimate the amount of data to be stored and then choose appropriate scheme, (let’s assume that one user uploads to a server 20mb per month (234Gb for 1000 users per year), and not popular files are not stored more than a year):

  • Stored data ~ 0.3Tb – 1.5Tb:we keep all the videos on each mirror. We have main mirror – server on which converted video always appears first and all other mirrors sync with it
  • Stored data ~ 1.5Tb – 3 Tb:
    All videos are stored in one central server, if the video is growing in popularity, it is poured into other mirrors
  • Stored data > 3Tb:
    Video is uploaded to the nearest mirror (example : assume that the video uploaded from China will be mostly popular in China, thus place it to the mirror in China) With the growing popularity of this video we will copy it to the server closest to the epicentre of popularity (example : Chinese living in the United States, the video file upload to a mirror located in the United States, watched videos in China, in this situation video file will be copied to the Chinese server)

This is not statistical numbers, they are for illustrative purposes. China cited as an example (nothing personal). Write an opinion in the comments…


Next, I will describe simple architecture DB:

id autoincrement field
login unique login
password encrypt password
email user email
actcode activation code
role ENUM(guest/user/admin)
status not active / active / disable
date_update date of last change profile
date_login date of last login
another fields e.g. first name, last name
id autoincrement field
user_id1 user ID
user_id2 user ID
status request / ok / cancel
date_create date of send request
date_update date of accept or denied request
id autoincrement field
title title of video file
file name of file on file system
status not convert / in process / ok
access public / members only / friends only / private
author_id ID of owner (users)
category_id ID of category (categories)
date_update date of last changes
another fields e.g. length, description
id autoincrement field
url mirror url
date_update date of last changes
file_id ID of file (files)
mirror_id ID of mirror (mirrors)
status current file status downloading / ok
date_update date of last changes
id autoincrement field
pid parent category ID
name name of category
another fields e.g. metadescription, metakeywords

id autoincrement field
word tag word
id autoincrement field
tag_id tag ID (tags)
file_id file ID (files)
id autoincrement field
author_id ID of owner (users)
file_id file ID (files)
message text of message

id autoincrement field
author_id ID of owner (users)
file_id file ID (files)
rate integer value, e.g. for 0 to 10

id autoincrement field
author_id ID of owner (users)
user_id ID of recipient (users)
type e.g. friend request-response / admin message
author_folder outbox/draft/delete
user_folder inbox/delete
user_status read or not

id autoincrement field
author_id ID of owner (users)
file_id file ID (files)
title title of link
description some description

A small note:

  • For the columns date_create and date_update using a gmdate (’Y-m-d H:i:s’) – GMT, it will make the life easier in the future when displaying the time on the site


How to gather a team to develop such a project best? I propose the following:

  • 2 PHP-Developer
  • Flash Developer / Designer
  • 1 UNIX-administrator
  • 1 Tester
  • 1 Manager


Static pages pages e.g. “Contact Us”, “Terms of Use” etc. 1h/page
Search file simple search by several params 6h
Tags Cloud 8h
View video FLV video player 16h
View comments 6h
Registration Registration and activation via e-mail 12h
Forgot password 2h
Login/Logout 2h
Upload file 14h
Record video Requried media server:

FMS, Wowza (from Feb 2007) or Red5 (opensource)
Progress bar 16h
Send Comment 4h
Rate File 2h
Bookmarks management create/edit/delete 8h
Users management The names and details of members who have been registered are listed showing the date their account was created and other user info.
Options are available for Administrator: view Member details, ban Members, search for existing users by First or Last name or Username etc.
Categories management 16h
Design 32h
Database Design 16h
Project Architecture Design 32h
Organize File Storage From 8h to 96h 8h
Convert process 20h
Environment setup configure web-server, convert-server, mirrors 40h
Development 256h
Testing 30%-50% of all development 85h
Management 10% of all time 40h
Total: 421h

So we have 421 hours, or approximately 2.5 months of development. Did you expect such a number? I thought it will be more :)

That’s very optimistic estimation that includes several assumptions:

  • the developers will use CMF system similar to phpXCore or Zend Framework
  • the developers are familiar with the CMF choosen (i.e. won’t learn in while coding)
  • the simplest file storage will be used (all mirrors store all files)

If development will be done from scratch you can easily multiply this assessment by 2.
Total, the project will cost at least $ 10,000…


The main problem is not in the system, main problem is drawing audience. Who will use your service if there is YouTube (and even PornoTube)? If you have ideas, write in comments…

At the time of writing this article domain was not registered. If you register it, send a beer at my home address… ;)

23 thoughts on “PHP CookBook: (YouTube clone)”

  1. Pingback: » links
  2. Excelente art?culo. Estoy interesado en desarrollar un sistema parecido, pero s?lo para Uruguay. Muchas gracias!!

  3. Со времен что-то перебор. Работу PHP-программера, я выполнел бы один максимум за 10 дней…

  4. 2JIEXA > без ошибок сначала научись писать.

  5. Where is video preview thumbnails ? They must be somewhere around files table.

  6. Thanks Anton. I will be reviewing this and get back to you. Btw, its not for porn…would you be able to assemble the team and the 10,000 cost you mentioned, is that anticipated expenses for the team and time you proposed or is that your fee?

  7. is already taken, therefore no beer for you mate:) Thanks for this example, I was looking for something like than for a long time. Now I know, how to make a good business plan for my customers. Cheers!

  8. Team

    How to gather a team to develop such a project best? I propose the following:

    * 2 PHP-Developer
    * Flash Developer / Designer
    * 1 UNIX-administrator
    * 1 Tester
    * 1 Manager

    I made a youtube clone, ALONE, it means, i m = 5 men ;)

  9. That was a rather interesting read, Anton. However, I have to say that I’m stunned at the hours you estimated for the single tasks, especially as general “testing” is added on top of that – which it should be.

    Take for instance the registration feature for new users. Do you really think it’s realistic to estimate 14 hours for that? I’d be interested to see where those numbers come from.


  10. @tim sweeny IMHO with experience of delivering such commercial experience the time estimates look largely correct. Underestimation is the bain of so many projects. The devil is in the detail after all.


  11. Thankyou for sharing! It is simply that easy to create a clone these days aint it? I provide a database for people to search for ready made scripts, but it is always great to see people still wanting to work from the ground up.

  12. is there anione who noe the opeation term for youtube? because
    i have an error after i run the program.

    youtube php ERROR An unsupported operation has been called

    ERROR An unsupported operation has been called –
    post variables received Array ( [operation] => search_all
    [maxResults] => 5 [startIndex] => 1 [searchTerm] => happy )

    need help urgently.. pls help..

Comments are closed.