A couple of months ago we started building out a Symfony 1.4 project for a client that involved allowing a “super admin” to add Doctrine models and columns at runtime. I know, I know, crazy/terrible/stupid idea but it mapped so well in to the problem space that we decided that a little “grossness” to benefit the readability of the rest of the project was worth it. Since users were adding models and columns at runtime we had to subsequently perform model rebuilds as things were added. Things worked fine for awhile, but eventually there were so many tables and columns that a single model rebuild was taking ~1.5 minutes on an EC2 large.
Initially, we decided to move the rebuild to a background cron process but even that began to take a prohibitively long time and made load balancing the app impossible. Then I started wondering is it possible to partially rebuild a Doctrine model for only the pieces that have changed?
Turns out it is possible. Looking at sfDoctrineBuildModelTask it looked like you could reasonably just copy the execute() method out and update a few lines.
Then, the next piece was just building the forms for the corresponding models. Again, looking at sfDoctrineBuildFormsTask it looked like it would be possible to extract and update the execute() method.
Anyway, without further ado here is the class I whipped up:
Using it is pretty straightforward, just call FastModelRebuild::doRebuild( array(“sfGuardUser”, “sfGuardUserProfile”) ); and thats it!
Anyway, fair warning I’d only do something like this if you “Know what you are doing” ™
As always, questions and comments are welcome.
Recently I was working on a project where we had a page which loads tons of data from numerous sources. I decided after a while that we wanted to AJAX each section of data so that the page would load a bit quicker. After splitting up the requests and sending them asyncronously, there was little improvement. I thought at first it may be due to the fact we were pinging a single API for most of the data multiple times, that wasn’t it. Maybe it was a browser limit? Nope was still far below the 6 requests most allow. I setup xdebug and kcachegrind and to my surprise it was the session_start() that was taking the most time on the requests.
I looked around the web for a while trying to figure out what in the world was going on. It turns out that PHP’s default session_start will block future session_starts for the same session until the session is closed. This is because the default method uses a file on the filesystem which it locks until you close it. If you want more information on this and how to close it you can read a bit more here.
We switched over to database based sessions and it fixed it. In symfony 1.4 the default session storage uses the file system, however switching over to sfPDOSessionStorage is very easy and quick.
I recently took the Symfony2 plunge and started working on a little fun side project (more on that later).
Anyway, this particular project involves sending out daily text messages using the rather awesome Twilio API so I decided to use a Symfony2 task for this. The documentation on how to actually add your own task is a bit sparse so I figured I’d share.
The process is actually pretty straight forward:
Here is the code for mine:
Posted In: Symfony
Symfony2 was released this past Thursday. This marks a huge advancement in the framework with tons of new features, better programming patterns, and much better performance. Symfony2 is now the most popular PHP project on GitHub and contributors are helping better it each day.
Since we are so excited for this release, we are going to take on one small free project for the person or company who submits the best idea and reason for their project. We’ll be picking the free project within one week of today. Shoot us an email with your project and reason you’d like it done for free.
Congrats to the entire Symfony2 team and we look forward to helping out with it!
Posted In: Symfony
Last week we launched RentPrefs a new take on renting an apartment. RentPrefs flips the process around by allowing renters to post their preferences and then allowing agents to match them with listings that fit their criteria.
Anyway, yesterday Xconomy did an awesome write up about them so definitely check it out. We also got a nice mention at the end there!
Posted In: Launch