I am trying to work on a web app that makes use of the Facebook PHP SDK with CakePHP as my framework.
Initially, I was pulling a bunch of facebook data in my controllers, but noticed that the Facebook API calls take a lot of time. So I thought about using cakePHP Shell Tasks in order to pull down the facebook data via scheduled cron jobs.
First a general question: is this the correct way to handle a situation like this? As in, using shell tasks to be used in cron jobs.
Secondly, currently my logic to connect to FB, pull down data, save into the db are all in controller actions. How can I access these actions from the shell Task?
Lastly, Facebook requires the user to be logged in to pull the data. If I use cron jobs, how will the user be logged in?
Thank you!
There are several ways in which you can address this issue.
The easiest would probably be an asynchronous AJAX request to get the data while the user is browsing your site (this requires of course that the user can browse your site without actually “leaving” the page).
If you’d go for delayed tasks with cron, (or beanstalkd, or delayed job, try Googleing them) you probably need some more privileges in your facebook integration, specifically the “offline access” feature. “This permission makes the access token returned by our OAuth endpoint long-lived.” You will then be able to make OAuth calls from a cake shell to retrieve the data.
Hope this helps!