Archive for October, 2006

Official WebThumb Contest rules published

Monday, October 23rd, 2006

Official contest rules for the WebThumb content are now up.

The contest runs until November 30th, and the top 5 submitters will all win upgraded WebThumb accounts. The top submitter will also win a copy of my book, Understanding AJAX.

I’ve you already commented on my last post about the contest make sure to get an official submission in before the 30th.

Great WebThumb article on Zend Developer Zone

Tuesday, October 17th, 2006

Cal Evans over at the Zend Developer Zone has written a very nice PHP5 wrapper and article about WebThumb. Read it for details and to get the code.

Oh and the WebThumb contest will be running until November 30th, all you have to do to win a free WebThumb account is to make something cool with WebThumb and release the code under a Open Source license. I’ll have more details and an official page up about it latter in the week.

New tutorial using HTML_AJAX and PEAR::Pager

Wednesday, October 4th, 2006

Lorenzo Alberton wrote a nice tutorial combining PEAR::Pager and HTML_AJAX. Its amazing how easy things get when you have some good libraries to rely on.

Webthumb API additions

Monday, October 2nd, 2006

If you wondered an API that requires polling isn’t a very good thing for scalability. On my current setup I can pretty easily handle about 20 status requests per second on top of my normal traffic, the problem is its not hard for a bad polling implmentation being run by one user to make that many requests.

To solve this problem im adding an addition to the Webthumb API that will allow you to skip polling all together. The basic idea is that your make an API request and when your thumbnail is complete i’ll make a GET request back too your server telling you that the request is complete.

So on the request side its just a matter of including an notify tag in your request block. An example is shown below:

<webthumb>
	<apikey>apikeyhere</apikey>
	<request>
		<url>webthumb.bluga.net</url>
                <notify>http://webthumb.bluga.net/sample/notify.php?secret=blahblahblah</notify>
	</request>
</webthumb>

I’m including a secret variable in the URL so that if someone found the URL of my notify script they couldn’t DOS me by making me download 100′s of different thumbnails from the server.

I’ve written a basic notify script to get you started. Feel free to use this script as a basis for whatever you need.

Update: Paths to thumbnails have changed so the download code listed here wont’ work. The new directory hash is:

<?php
substr($id,-2).'/'.substr($id,-4,-2).'/'.substr($id,-6,-4)
?>

Which means if your job id is: wt4761c8f914559 then the directory is: http://webthumb.bluga.net/data/59/45/91/

<?php

// this is a really simple notify script
// it downloads the specified thumbs for a job and puts them in the storage dir
// if you want to store files based urls etc you'll need to store the id at request time
// then do a mapping in this script

// download options
// zip     - all sizes in a zip
// zipAuto - zip download and auto uncompress
// large   - 640x480
// medium2 - 320x240
// medium  - 160x120
// small   - 80x60
$downloadType = 'zipAuto';

// secret id im using to make sure no one has me download every thumb etc
$mysecret = 'changeme';

// directory to write files too
$storageDir = 'tmp';

// webthumb base url
$url = 'http://webthumb.bluga.net/data/';

// unzip command
$unzipCommand = 'unzip';

// END CONFIG
if (!isset($_GET['id']) || !isset($_GET['secret'])) {
    exit;
}

if ($mysecret == 'changeme') {
    echo "Configure notify script";
    exit;
}

$jobId = $_GET['id'];
$secret = $_GET['secret'];

if ($secret !== $mysecret) {
    echo "bad secret";
    exit;
}

$jobDir = substr($jobId,-4);

switch($downloadType) {
    case 'zip':
    case 'zipAuto':
        $file = "$jobId.zip";
        break;
    default:
        $file = "$jobId-thumb_$downloadType.jpg";
        break;
}

// this is the simplest possible download code, curl, PEAR http_request might be better
// will only work if allow_url_fopen is on
$contents = file_get_contents($url.$jobDir."/$file");
file_put_contents($storageDir."/$file",$contents);

if ($downloadType == 'zipAuto') {
    exec("cd $storageDir && $unzipCommand $file");
    unlink($storageDir."/$file");
}

?>

Let me know if you find any major bugs in the code. There are always going to be cases where the polling API makes more sense (command line utils etc) but I think this notify API should work great for any application integration.

This circle expands additional navigation