FMFindQuery()

At work we use the very handy FX.php library to develop sites in PHP with FileMaker as the backend. Due to an upcoming change in the way course numbers are represented in our student information system, I needed to ‘extend’ a found set in one of my models. From reading the FX.php documentation, I got the impression that it wasn’t possible to do using FX.php. So, I took a look at the official FileMaker documentation on Custom Web Publishing with XML to see if this was a limitation of FileMaker server, or just something that hadn’t made it into FX.php. What I came across was the ‘-findquery’ and ‘-query’ parameters which allow you to do a “compound find request” (so it is supported!). I couldn’t find anything about how to do this in the FX.php documentation, so I decided that I would take a look at the source code to see if it was there, and if not, make an attempt at adding it.

Turns out there is a function called FMFindQuery that is not in the FXFunctions documentation. It took some trial and error, but I was able to figure out how it worked and wanted to share what I learned. Here is a simple example of the use of FMFindQuery that is analogous to what I was trying to accomplish. According to the official CWP documentation, the ‘-query’ parameter is where you provide the query names and search criteria for your request. Each search request (or set of search requests) should be enclosed in parentheses. AND search requests should be separated by a comma (make sure there are no spaces between your commas, or it won’t work!). OR search requests are separated by semi-colons. You can perform an OMIT request by prefixing your request with an exclamation point like so !(q3). Here is an example:

This request would find all Pets where ‘PetName’ is ‘Spot’ AND ‘Breed’ is ‘Shiba Inu’ OR ‘PetName’ is ‘Spot’ AND ‘Breed’ is ‘Corgi’.

After figuring out how it all worked, I decided to fork the FX.php project on Github and add a section to the FXFunctions.rtf file about FMFindQuery(). Today, I got an email that my change had been merged back into the main FX.php repo. A small contribution, but it is my first contribution to open source software on Github!

FMFindQuery()

MidWest PHP 2013

So, the discussion about djcelery integration into rpgmaker.net never quite came…I’ll get back to that one in the future. In the meantime, lets talk PHP!

Over the weekend of March 2nd – 3rd I attended my first conference as an actual employed developer! Along with a co-worker, I traveled to the University of Minnesota to take part in the first (annual?) MidWest PHP conference. It was definitely an interesting experience. I attended talks on using Backbone.js, Websockets, enterprise PHP architecture, Symfony2, Laravel, Drupal (gross), and building testable PHP applications. My favorite talk was, by far, the opening keynote by Joel Clermont titled, “Learning how to Learn”. It was a bit of a meta talk about how to approach learning as a developer and I hope to apply some of the things Joel went over in my personal and professional life. You can view the slides here: Learning How to Learn on Speaker Deck. After that talk, my next favorite would have had to been the “Building Testable PHP Applications” talk by Chris Hartjes. Chris is a very passionate guy and that really came across in his talk. I’ll definitely be putting some of the best practices and methods he talked about into practice the next time I write pure OOP PHP. You can view the slides for Chris’ talk here: Building Testable PHP Applications on Speaker Deck.

Overall the conference was a great learning experience and I hope to attend again next year if possible.

MidWest PHP 2013

Is that really a good idea?

I’ve been itching to write an app using the Dropbox API for quite a while and I’ve had an idea bouncing around in my head for well over a year. I started a new job back in February of 2010 and didn’t have Dropbox setup on my work computer (and I wasn’t sure I wanted to set it up) but there was a file I wanted to upload. I could have just downloaded it locally and then uploaded it using the Dropbox website, but then I thought to myself, Why can’t I just enter the path of the file into the Dropbox website and have Dropbox download it for me? In my typical OCD fashion I spent months coming up with a good name and design before ever working on a single line of code. As I started to actually work on it, I ran into a few hurdles which made me think it wasn’t such a good idea after all.

The first problem I ran into was that not every site sends the same HTTP headers with their file downloads. This made it difficult to be able to consistently get the information I wanted to store about the download. I ended up using PHP’s get_headers function to retrieve the file headers and parse out the filename, direct download link, file size, content type, etc. This seemed to work for most downloads, and for those that did not send a Content-Disposition header, I was able to extract the filename from the URL easily enough.

Then I tried to use a file download from MediaFire. None of the workarounds I had in place worked. I found a few posts on Stackoverflow about parsing the HTML/JS to get the direct download link, but even when I had the link I still wasn’t able to get the file correctly. Then I thought, does MediaFire have an API? Yes, yes they do. Great! I can parse the URL to look for MediaFire files and use their API to download them. But then what about all the other file hosting services? I haven’t done any testing with Rapidshare or other services, but I’ll admit, just the thought of having to develop a customized solution for each host makes me cringe.

I haven’t even touched on the logistics of queueing up downloads and sending them to Dropbox for however many people might find this useful. Then I have to consider the storage space required to host the downloads (or the memory to stream them) and the bandwidth to send them to Dropbox. If I were to continue with the project I would probably use Amazon’s cloud services to host the site. It would be a good learning opportunity as I’ve never worked with any of Amazon’s services before and I feel that this idea is perfect for AWS/S3 (or EB)/SWF/SQS.

Next up, my itch to use the Dropbox API in something pushes me to integrate it into rpgmaker.net using django-celery!

Is that really a good idea?