Facebook PHP Api Performance
If you’re developing for the Facebook API, you’ll have noticed by now that you probably want to have their F8 platform cache things in people’s profiles, using the ref FBML, which looks like this:
<fb:ref url="http://your-site.com/resource"/>
<fb:ref handle="MyItemToCache#1"/>
With the ref-url construction, Facebook will visit your URL and cache it. You can call their API to refresh the url when you would like. With the superior ref-handle construction, you pass (handle, value) pairs to Facebook to cache. This saves you from being hammered by Facebook on all the refresh callbacks because you can just fire and forget your ref-handle updates.
Here is an example from my Stock Quotes Facebook Application, which refreshes its tickers on a regular interval:
Refreshed 1859 stock tickers in 5 seconds!
How on earth can I refresh 371.8 ref handles a second? You certainly can’t; the performance of the standard API is 4.60 ref handles a second. But, I’ve hacked the Facebook PHP Client to give you 80x the ref-refreshing performance. The trick is to parallelize the Facebook api calls, using curl_multi instead of plain old curl. You create a new Facebook API client called $fb and then:
$fb->openTransaction();
// your calls to set / refresh refs
$results = $fb->closeTransaction();
You get back the $results array as well, which you can check for errors if you’d like. If you want, you can download my modified client for your own personal use. Please let me know if there are any bugs!
This entry was posted on Saturday, June 16th, 2007 at 5:48 pm and is tagged with stock tickers, ref url, value pairs, facebook, fb, interval, personal use, lt, array, bugs, fbml, profiles, earth. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback.
21 Responses to 'Facebook PHP Api Performance'
Leave a Reply
Fresh, related resources:
- Tech Times #190 - JavaScript & Standards / Python for PHP Developers
But the Selectors API only lets you use CSS selectors supported by the browser -- no more, no less. Libraries that support additional, non-standard selectors will not be able to deliver this performance boost. ... - Early Adopters Still Spend More Time With Microsoft Than Google ...
Facebook holds a surprisingly strong lead over other websites, with nearly three times as much usage as Wikipedia’s English site. Also notable is Twitter.com’s usage (this is the site itself, not the API, which reportedly sees ten times ... - [offer] Apress Ebook Collection Pack
Expert.VB.2005.Business.Objects.2nd.Edition.May.2006.eBook-BBL Apress.Facebook.API.Developers.Guide.Mar.2008.eBook-BBL Apress.Facebook.API.Developers.Guide.Mar.2008.RETAiL.eBOOk-sUppLeX Apress.Foundations.of.ASP.NET.AJAX.Nov.2007. ... - Facebook on LAMP software engineer and developers / Familybuilder ...
Candidates will work with the Facebook API and the OpenSocial API with applications hosted on Linux/Apache/MySQL/PHP. This is a rapid development environment that could be described as both fun and rewarding. ... - #1837 Automated merge with http://hg.netbeans.org/main (phejl ...
cnd.dwarfdiscovery/test/unit/src/org/netbeans/modules/cnd/dwarfdiscovery/provider/LogReaderTest.java cnd.modelimpl/src/META-INF/services/org.netbeans.modules.cnd.api.model.services. ...

on July 6th, 2007 at 10:42 am
How do I use this? The code as posted looks like it replaces the existing FacebookRestClient class. But since that class contains all the functionality to set/refresh refs, I am not sure how to accomplish this.
on August 2nd, 2007 at 6:29 pm
Would be cool if you could post a unified diff, but this is great regardless. Thanks!
on August 15th, 2007 at 7:54 pm
Hi
I think you simply replace the current methods etc in the Real FB class, and add in any other stuff that isnt there like the class attributes
Ian
on August 16th, 2007 at 12:12 am
You may wish to test this when running some FQL statements also I had some strange results, in fact I don’t think it worked at all
Ian
on September 8th, 2007 at 2:44 pm
How’d you do this? Can you go into details… show more code on where to change things?
on September 18th, 2007 at 7:58 am
Good of you to let us know this can be done…. better if you could show us the modded code….
on September 18th, 2007 at 1:50 pm
Yeah, it’s posted–check the link.
on September 29th, 2007 at 6:54 am
Is this using the latest update - published on the 26th September?
Please state this on the site and you should add a version within the file.
Good work
on October 1st, 2007 at 1:54 pm
Hi, the sample code zip file seems to be corrupt. I can’t decompress it.
on October 1st, 2007 at 2:01 pm
Anyone got a PHP4 version, or can you do this in PHP4?
on October 1st, 2007 at 5:05 pm
I hate to be mean stefan, but you’re a noob:
[root@fc624389 ~]# wget elliottback.com/wp/wp-content/uploads/2007/09/facebookapi_php5_restlib.zip
–18:04:52– elliottback.com/wp/wp-content/uploads/2007/09/facebookapi_php5_restlib.zip
Resolving elliottback.com… 66.240.243.89
Connecting to elliottback.com|66.240.243.89|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 3939 (3.8K) [application/zip]
Saving to: `facebookapi_php5_restlib.zip’
100%[=======================================>] 3,939 –.-K/s in 0s
18:04:52 (250 MB/s) - `facebookapi_php5_restlib.zip’ saved [3939/3939]
[root@fc624389 ~]# unzip facebookapi_php5_restlib.zip
Archive: facebookapi_php5_restlib.zip
inflating: facebookapi_php5_restlib.php
[root@fc624389 ~]#
on October 4th, 2007 at 3:32 pm
Quick question - I am developing a Facebook application that requires the profile box to be updated on any profile view, based on the user that is currently logged in(not the user that has the profile box).
What would you suggest as the best way to do this?
on October 22nd, 2007 at 6:22 pm
Elliott, are you getting the stock data from Yahoo! for free? Is there a limit on how many requests you can make?
on October 22nd, 2007 at 6:52 pm
Yes, I am. I don’t think there’s a limit.
on November 12th, 2007 at 2:17 pm
Are you currently accepting advertising on your website elliottback.com?
Thank you,
Nicole
Marketing Manager
ZTMC, INC.
on December 18th, 2007 at 3:36 am
It seems some people are having trouble with the Facebook Data Store API. I have abstracted its behaviour into several classes. Although incomplete, the WMSFacebookDataStore API allows rudimentary CRUD access to Facebook’s database.
www.davidjarvis.ca/facebook/
www.davidjarvis.ca/facebook/docs/
Data Store classes:
WMSFacebookDataStore
WMSFacebookDataStoreAssociation
WMSFacebookDataStoreAssociationLink
WMSFacebookDataStoreObject
WMSFacebookDataStoreProperty
WMSFacebookDataStoreRow
Core classes:
WMSFacebook
WMSFacebookApplication
WMSFacebookFriend (stub)
WMSFacebookMessage (stub)
WMSFacebookObject
WMSFacebookProfile (stub)
WMSFacebookUser
At the very least it shows how to use Facebook’s Data Store API.
on January 2nd, 2008 at 9:22 pm
Great hack, just tried it and unlike comment above, seems to work fine with the fql I’m using. I did have to take out a CURL option that wasn’t supported by my hosts version of php curl (CURLOPT_TCP_NODELAY).
Just a thought though, you don’t throw FacebookExceptions with relevant failed calls (i.e. error results etc) in the closeTransaction(). What were your thoughts behind this?
on January 30th, 2008 at 7:29 pm
Isn’t this obsolete now due to Facebooks API batch calling?
on February 11th, 2008 at 12:29 am
is the ref-handle construction really superior to the ref-url construction? i ran some basic tests and it seems not…
if you push to all your users profiles, then your server only gets hit once when you call the fbml_refreshRefUrl api function. where is the hammering you speak of?
on February 28th, 2008 at 3:21 am
[…] If you’re using fb:ref (which you SHOULD be), you probably want to be using the “push” method, using named handles. Add the php curl_multi hack for performance, and you’ll be off and running. […]
on April 18th, 2008 at 2:33 am
how can i get original image in facebook album using facebook api?