Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What in the world of facebook is rsrc.php?

http://static.ak.fbcdn.net/rsrc.php/117600/css/base.css

http://static.ak.fbcdn.net/rsrc.php/z4HBM/hash/3krgnmig.swf

http://b.static.ak.fbcdn.net/rsrc.php/z23ZQ/hash/3ls2fki5.xml

http://static.ak.fbcdn.net/rsrc.php/z7O0P/hash/4hw14aet.png

What does rsrc.php really does? I know that rsrc stands for resource and rsrc.php/z[random]/hash or css/file.extenstion loads a file from somehwere.

Assuming /hash/ or /css/ is a folder which keeps the files like .xml .png .swf but whats with z[random] thing and why they want to load a file from a php? Is it for something like version control for the file or what? If so how to do it (in a simpler way)?

like image 900
kornesh Avatar asked Dec 12 '10 13:12

kornesh


2 Answers

There is a my version of rsrc.php

$request = basename($_SERVER[REQUEST_URI]);
$dotIndex = strrpos($request, ".");
$extension = substr($request, $dotIndex+1);
switch ($extension):
    case 'js': $content_type="application/javascript"; break;
    default: $content_type="text/css"; break;
endswitch;
$file = Gdecode($request);
$script_file = dirname(__FILE__)."/".$extension."/".$file.".".$extension;
$fp = @fopen($script_file, "r");
if($fp):
    fclose($fp);
    header('Content-type: '.$content_type);
    echo file_get_contents($script_file);
endif;
like image 67
Ivars Rudaks Avatar answered Oct 21 '22 15:10

Ivars Rudaks


rsrc.php is used by Facebook for version control of all static files, especially images, javascript, and stylesheets. This allows Facebook to apply changes to the main application stack including changes to static content files without breaking functionality for users who are running off an old cached version. It is built into the Facebook architecture as part of the Haste system.

  1. Reference To Code Function Identification By Original Developer
  2. Recommended Process For Managing Static Resources (phabricator.com)
like image 26
Chris Rutherfurd Avatar answered Oct 21 '22 16:10

Chris Rutherfurd