-5

Is it possible upload a file using gearman ? Bye.

Aly
  • 117
  • 1
  • 4
  • I dont see why not. Could you be more specific on what sort of problem you are having? – dabito Nov 30 '10 at 20:22
  • I'm looking for a little example just an hint. The main problem is I don't find the way to pass the $job->workload() to the worker may be serialize($_FILE) ? – Aly Dec 01 '10 at 18:15

2 Answers2

3

Use standard php to upload the file. Read the bytes of the file into a variable and pass to the server.

A client has some form of blob data and wants to farm out the processing of the data to the cloud. To do so, it makes a connection to the Server and requests that the server perform some function on that data.

Read the docs.

Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
0

This reads the file using file_get_contents, it is passed on to the do() method of GearmanClient. There's no need to "upload" the content, it will be transmitted to gearman, and further to the worker.

client.php

<?php
$client= new GearmanClient();
$client->addServer();
print_r(unserialize($client->do("wordcount", file_get_contents('filename.txt'))));

worker.php

<?php
$worker= new GearmanWorker();
$worker->addServer();
$worker->addFunction("wordcount", "worker_function");
while ($worker->work());

function worker_function($job)
{
  return serialize(array_count_values(str_word_count($job->workload(),1)));
}
Peter Lindqvist
  • 10,122
  • 3
  • 41
  • 60