php gearman文件上传

发布于 2024-10-05 23:39:57 字数 31 浏览 0 评论 0原文

是否可以使用 gearman 上传文件? 再见。

Is it possible upload a file using gearman ?
Bye.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风不识月 2024-10-12 23:39:57

使用标准 php 上传文件。将文件的字节读入变量并传递到服务器。

客户端拥有某种形式的 blob 数据
并希望将加工外包出去
的数据到云端。为此,它
与服务器建立连接并
请求服务器执行一些操作
对该数据进行函数处理。

阅读文档。

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.

顾冷 2024-10-12 23:39:57

这使用 file_get_contents 读取文件,并将其传递给 GearmanClient 的 do() 方法。无需“上传”内容,它将传输给 gearman,并进一步传输给工人。

客户端.php

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

工作者.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)));
}

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)));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文