教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php能用hadoop吗

php能用hadoop吗

发布时间:2020-08-14   编辑:jiaochengji.com
教程集为您提供php能用hadoop吗等资源,欢迎您收藏本站,我们将为您提供最新的php能用hadoop吗资源
Hadoop是一个由Apache基金会所开发的分布式系统基础架构,用户可以在不了解分布式底层细节的情况下,开发分布式程序。充分利用集群的威力进行高速运算和存储。

虽然Hadoop是用java写的,但是Hadoop提供了Hadoop流,Hadoop流提供一个API,,允许用户使用任何语言编写map函数和reduce函数。 (推荐学习:PHP视频教程)

Hadoop流动关键是,它使用UNIX标准流作为程序与Hadoop之间的接口。因此,任何程序只要可以从标准输入流中读取数据,并且可以把数据写入标准输出流中,那么就可以通过Hadoop流使用任何语言编写MapReduce程序的map函数和reduce函数。

例如:

bin/hadoop jar contrib/streaming/hadoop-streaming-0.20.203.0.jar -mapper /usr/local/hadoop/mapper.php -reducer /usr/local/hadoop/reducer.php -input test/* -output out4

Hadoop流引入的包:hadoop-streaming-0.20.203.0.jar,Hadoop根目录下是没有hadoop-streaming.jar的,因为streaming是一个contrib,所以要去contrib下面找,以hadoop-0.20.2为例,它在这里:

-input:指明输入hdfs文件的路径

-output:指明输出hdfs文件的路径

-mapper:指明map函数

-reducer:指明reduce函数

mapper函数

mapper.php文件,写入如下代码:

#!/usr/local/php/bin/php
<?php
$word2count = array();
// input comes from STDIN (standard input)
// You can this code :$stdin = fopen(“php://stdin”, “r”);
while (($line = fgets(STDIN)) !== false) {
    // remove leading and trailing whitespace and lowercase
    $line = strtolower(trim($line));
    // split the line into words while removing any empty string
    $words = preg_split('/\W/', $line, 0, PREG_SPLIT_NO_EMPTY);
    // increase counters
    foreach ($words as $word) {
        $word2count[$word]  = 1;
    }
}
// write the results to STDOUT (standard output)
// what we output here will be the input for the
// Reduce step, i.e. the input for reducer.py
foreach ($word2count as $word => $count) {
    // tab-delimited
    echo $word, chr(9), $count, PHP_EOL;
}
?>

以上就是php能用hadoop吗的详细内容,更多请关注教程集其它相关文章!

  • 本文原创发布教程集,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    php能用hadoop吗
    php程序员可以转java吗?
    php可以考什么证书?
    如何搭建JAVA线程池管理及分布式HADOOP调度框架教程
    php如何处理大数据高并发
    为什么大部分程序员看不起php语言?
    golang 大数据平台_大数据平台是什么?有哪些功能?如何搭建大数据平台?
    php可以写AI吗?
    php能用来调用js代码吗
    html能触发php函数吗?

    [关闭]
    ~ ~