If someone wrote the lore of BKWLD, the turning point chapter in our story would be the day Robert was hired. It's been Robert's technical direction and dedication to learning new technology that has kept BKWLD at the forefront of our industry.
WebGrind is a great tool for analyzing your PHP app and finding where slow down is occurring. As stated on the Google Code site for the project, it is a “ Xdebug profiling web frontend.” Here’s the steps I took getting it working in MAMP.
Download the latest Xdebug binaries for your OS from Komodo. They will be labeled as “PHP Remote Debugging” for Mac OS X. When you unzip it, you’ll see the xedbug.so file.
Copy the xdebug.so for your PHP version to your extensions directory (/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/xdebug.so)
Find your php.ini file (Applications/MAMP/conf/php5/php.ini)
Add the following lines to your php.ini configuration (MAMP):
That’s it! There is some useful additional ini settings I found in this blog post:
# Set the filenames generated by xdebug to use REQUEST_URI instead
# of the apache process number
# so all requests to the same page end up in the same file.
xdebug.profiler_output_name = cachegrind.out.%R # Set xdebug to append data to files instead of overwriting,
# this means you can view aggregate
# function calls over multiple requests.
xdebug.profiler_append = TRUE
I’ve already found some major instances of slowdown that can be cleaned up in the application I’m testing.
The SEA office flew down to Sacramento before the holidays to meet in person as a group, plan the next year, and have fun together over 4 days. My shoulder was (and is) out of commission (bike accident) so I missed this years ski trip to Tahoe; it sounded like everyone got along fine without me though. Going up to Tahoe is sort of a BKWLD tradition at this point, I think this was the 4th or 5th time. Of all the photos I took, these came out the least blurry, which is pretty sad. If someone with more skills and a better camera has some shots, please replace mine in this post!
Happy New Year everyone, looking forward to an amazing 2010!
I recently learned that the http spec suggests browsers only open two simultaneous connections to a given subdomain at a time. I haven’t tested to see how widely adopted this is. Though I have noticed in Safari, looking at the activity viewer, that if the page requests many large assets (like a flash audio player where the user has advanced through tracks quickly), file requests start to queue up. In a recent blog by Campaign Monitor, they mention that they server images from multiple subdomains at a time so the web browser opens up more connections at time. You don’t even need multiple servers. You could wildcard the subdomains on your webserver and serve up a unique subdomain. As pointed out on Stack Overflow, you don’t want to choose a completely random subdomain on every request or the browser can’t cache the image. It’s a pretty extreme optimization technique , though something to keep in your toolbox.
It’s been a two day quest, but I’ve finally gotten our web server to talk to a remote SQL server over VPN. I wish I could document the steps as a how to (I’d like it for myself if I have have to do this again), but I’ve tried so many things I’m not sure which steps are true dependencies and which are extraneous. First, the server in question is a LAMP server, running Plesk, hosted at Media Temple. For the most part, it’s a vanilla configuration. Here’s some of the things I learned in the process of getting this up:
The VPN is of the Cisco type, but using their linux software was a dead end. I couldn’t get it to compile, it needed kernel headers and patches and on and on. Eventually, I was directed to using VPNC. There are scripts that convert pcf files to the format VPNC uses. Also, you can store the VPN password within the config file, which is perfect for my situation. If I feel like enduring further pain, it may be useful to get this working locally and stop using the Cisco Mac client altogether.
It turns out you need to be running as root to use VPNC. Thus, for the users that would be running this, I had to add entries to the sudoers file. I made it passwordless because I knew I’d be calling it from PHP.
I had to allow /usr/local/sbin as an open_basedir in php so that I could call VPNC.
From exec(), I needed to use the full path to VPNC.
Lastly, and this was particularly painful because I knew I was sooo close at this point, I had to comment out “Defaults requiretty” within sudoers. When this is on, it prevents you from running sudo outside of the command line.
This was a very frustrating journey so hopefully this helps someone else. Or me in the future.
Say you have a table of names that you want to alphabetize. Of course you could SELECT and ORDER BY name ASC. Lets assume that’s not an option and you want to save their alphabetical order in a special column so then you can ORDER BY this column. This might be useful if you have an application where users can manually order their items but you give them them option to reset to alphabetical. Here’s what your table looks like:
people
- id (int)
- name (varchar)
- sort (int)
Here’s how you can populate that sort column with integers that, when ordered by, put the results in alphabetical order:
SET @i=0;
UPDATE people
INNER JOIN (
SELECT id, @i:=@i+1 AS i FROM people ORDER BY name ASC
) counter ON counter.id = people.id
SET people.sort = counter.i;
The SET command initializes a variable. The subquery orders the list and adds a new column (i) that counts off each row effectively. Then the outer query joins on this by the PRIMARY id so that we match the ordered row from the subquery with the outer query. And lastly, we store the i value back in the table.
I’ve never understood (well, I’ve never looked into) why MySQL defaults to that swedish collation. If your tables are a mix of collations, here is a nice php script that will convert all the tables to the collation of your choosing. It even has a nice GUI you use in the web browser. Download the script here (courtesy of phoca.cz).
We use Amazon S3 as an easy and cheap CDN on many projects. Here’s some interesting things I learned recently while researching how to stop direct downloading or linking to media files:
Any file on S3 can be turned into a torrent by adding ?torrent to the filename. As in http://bucket.s3.amazonaws.com/myfile.zip?torrent. I read about this over here.
S3Stat looks like a useful tool for viewing your S3 logs. In particularly, checking for direct linking from other sites.
You can make auto expiring links using S3 (documentation here). This is the meat of what I wanted to find out. Using the Query String Request Authentication (page 24 of the PDF) you can specify an expire time for a link. As I take it (and we haven’t implemented this yet, so I’m not positive), you would set the read access of the file to “Authenticated Users.” Then you would construct the URL to the file using your public AWS access key, the expire time, and then a signature that includes a hash of your request with the expire time and your private key. So if you set the expire time to something only a few seconds after the current timestamp, that link should not be useable again.
I don’t often batch import layered files (PSD, PNG) into Flash or even copy graphics into it. But what I DO find really handy is copying text between the apps. This worked in CS3 but it’s gotten better (more accurate) in CS4. You can copy a whole group in and the font, size, and color are all maintained (or close enough, you usually have to nudge line height). This saves tons of time when you’re populating a whole FLA from a text heavy design while keeping the text editable for the inevitable copy change. Notice in this video how I can bring in multiple text boxes at a time.
Doing research for a pitch I found the USDA National Nutrient Database. I haven’t found an elegant API for it, but at the very least you could use curl and screen scrape what you need. But wow, it’s deep. A great resource for providing data for a health related site. It looks like you can download the database whole and implement it locally.