File: image_thumbnail_client_task.php

package info (click to toggle)
php-gearman 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 320 kB
  • ctags: 330
  • sloc: ansic: 3,657; php: 586; xml: 286; makefile: 4
file content (69 lines) | stat: -rw-r--r-- 1,546 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
 * Gearman PHP Extension
 *
 * Copyright (C) 2008 James M. Luedke (jluedke@jamesluedke.com)
 *                           Eric Day (eday@oddments.org)
 * All rights reserved.
 *
 * Use and distribution licensed under the PHP license.  See
 * the LICENSE file in this directory for full text.
 */

/* create our object */
$gmc= new GearmanClient();

/* add the default server */
$gmc->addServer();

/* set a few callbacks */
$gmc->setCreatedCallback("thumb_created");
$gmc->setCompleteCallback("thumb_complete");
$gmc->setFailCallback("thumb_fail");

for ($x= 0; $x<20; $x++)
{
    $data[$x]['src']= $_SERVER['argv'][1];
    $data[$x]['dest']= "$x.jpg";
    $data[$x]['x']= ((80+1)*($x+1));
    $data[$x]['y']= NULL;
}

/* fire off each job */
foreach ($data as $img)
{
    /* NOTE: if you want to asynchronously queue jobs use
    ** $task= $gmc->add_task_background("shrink_image", serialize($img));
    ** however keep in mind that your complete callback will not get called */
    if (! $gmc->addTask("shrink_image", serialize($img)))
    {
        echo "ERROR RET: " . $gmc->error() . "\n";
        exit;
    }
}

if (! $gmc->runTasks())
{
    echo "ERROR RET:" . $gmc->error() . "\n";
    exit;
}
echo "DONE\n";
exit;

function thumb_created($task)
{
    echo "CREATED -> job: " . $task->jobHandle() . "\n";
}

function thumb_complete($task)
{
    echo "COMPLETE -> job: " . $task->jobHandle() . 
         " new_file: " . $task->data() . "\n";
}

function thumb_fail($task)
{
    echo "FAIL job: " . $task->jobHandle() . "\n";
}

?>