PHP calls the shell to upload local files into Hadoop's HDFs

Source: Internet
Author: User
Tags hadoop fs
PHP calls the shell to upload local files into Hadoop's HDFs

Originally used to upload thrift, but its low upload efficiency, another person heinous, had to choose other methods.

?

Environment:

PHP operating Environment for Nginx + PHP-FPM

?

Because Hadoop has permission control enabled, there is no permission to use PHP directly to invoke Shel for uploading. The PHP execution command appears to be nobody for both the account and the level of PHP running. Therefore, there are two workarounds: first, create a directory in the shell of Hadoop and assign the owner of the directory to the nobody user of the nobody group. Two, the original directory permission to release, using 777. The following is a detailed procedure:

?

Method one:./hadoop fs-chown-r Nobody:nobody/resources

Note:/resources is a user directory and needs to be changed according to circumstances

?

Method two:./hadoop fs-chomod-r 777/resources

Note:/resources is a user directory and needs to be changed according to circumstances

?

How PHP calls the shell:

Public Function Uploadbyshell ($local, $hdfs) {$shell =  "Sh/usr/local/hadoop/hadoop-0.20.2/bin/hadoop FS- Copyfromlocal ". $local. " " . $hdfs; $shell. = "; Sh/usr/local/hadoop/hadoop-0.20.2/bin/hadoop fs-chmod 777 ". $hdfs $res = Null;system ($shell, $res), $flag = false;if ($res = = "0") {$flag = true;} return $flag;}
?

?

?

?

?

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.