"use strict";(self.webpackChunkopendal_website=self.webpackChunkopendal_website||[]).push([[2577],{4241:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>d,default:()=>u,frontMatter:()=>p,metadata:()=>t,toc:()=>h});const t=JSON.parse('{"id":"bindings/php","title":"PHP \ud83d\udea7","description":"","source":"@site/docs/20-bindings/php.mdx","sourceDirName":"20-bindings","slug":"/bindings/php","permalink":"/bindings/php","draft":false,"unlisted":false,"editUrl":"https://github.com/apache/opendal/tree/main/website/docs/20-bindings/php.mdx","tags":[],"version":"current","lastUpdatedBy":"Friends A.","lastUpdatedAt":1741941961000,"frontMatter":{"title":"PHP \ud83d\udea7"},"sidebar":"docs","previous":{"title":"OCaml \ud83d\udea7","permalink":"/bindings/ocaml"},"next":{"title":"Python","permalink":"/bindings/python"}}');var i=s(6070),l=s(5658),r=s(8699);function o(e){const n={a:"a",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",header:"header",img:"img",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,l.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.header,{children:(0,i.jsx)(n.h1,{id:"apache-opendal-php-binding-wip",children:"Apache OpenDAL\u2122 PHP Binding (WIP)"})}),"\n",(0,i.jsx)(n.p,{children:(0,i.jsx)(n.a,{href:"https://opendal.apache.org/bindings/php/",children:(0,i.jsx)(n.img,{src:"/img/external/552ab0d9376d217ab2e8b0ade233afb8.svg",alt:""})})}),"\n",(0,i.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-php",children:'use OpenDAL\\Operator;\n\n$op = new Operator("fs", ["root" => "/tmp"]);\n$op->write("test.txt", "hello world");\n\necho $op->read("test.txt"); // hello world\n'})}),"\n",(0,i.jsx)(n.h2,{id:"requirements",children:"Requirements"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"PHP 8.1+"}),"\n",(0,i.jsx)(n.li,{children:"Composer"}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"install-extension",children:"Install Extension"}),"\n",(0,i.jsxs)(n.p,{children:["We use ",(0,i.jsx)(n.a,{href:"https://github.com/davidcole1340/ext-php-rs",children:"ext-php-rs"})," to build PHP extensions natively in Rust, it's different from the traditional PHP extension development and cannot be installed using ",(0,i.jsx)(n.code,{children:"pecl"})," or ",(0,i.jsx)(n.code,{children:"phpize"}),". Before installing the extension, it is necessary to install Rust and Cargo. For instructions on how to install them, please refer to ",(0,i.jsx)(n.a,{href:"https://www.rust-lang.org/tools/install",children:"Rust's website"}),"."]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsx)(n.li,{children:"Clone the repository"}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"git clone git@github.com:apache/opendal.git\n"})}),"\n",(0,i.jsxs)(n.ol,{start:"2",children:["\n",(0,i.jsx)(n.li,{children:"Build the opendal-php extension"}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"cd opendal/bindings/php\ncargo build\n"})}),"\n",(0,i.jsxs)(n.blockquote,{children:["\n",(0,i.jsxs)(n.p,{children:["don't forget to add ",(0,i.jsx)(n.code,{children:"--release"})," flag for production use."]}),"\n"]}),"\n",(0,i.jsxs)(n.ol,{start:"3",children:["\n",(0,i.jsx)(n.li,{children:"Enable extension for PHP Manually"}),"\n"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:'cd opendal\n\n# Linux\ncp target/debug/libopendal_php.so $(php -r "echo ini_get(\'extension_dir\');")/libopendal_php.so\necho "extension=libopendal_php.so" >> $(php -r "echo php_ini_loaded_file();")\n\n# macOS\ncp target/debug/libopendal_php.dylib $(php -r "echo ini_get(\'extension_dir\');")/libopendal_php.dylib\necho "extension=libopendal_php.dylib" >> $(php -r "echo php_ini_loaded_file();")\n\n# Windows\ncp target/debug/libopendal_php.dll $(php -r "echo ini_get(\'extension_dir\');")/libopendal_php.dll\necho "extension=libopendal_php.dll" >> $(php -r "echo php_ini_loaded_file();")\n'})}),"\n",(0,i.jsxs)(n.ol,{start:"4",children:["\n",(0,i.jsx)(n.li,{children:"Enable extension for PHP using cargo-php"}),"\n"]}),"\n",(0,i.jsxs)(n.p,{children:["You can also use cargo-php directly to install the extension, see ",(0,i.jsx)(n.a,{href:"https://davidcole1340.github.io/ext-php-rs/getting-started/cargo-php.html",children:"cargo-php"})," for more details."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"cargo install cargo-php\ncd opendal/bindings/php\ncargo php install\n"})}),"\n",(0,i.jsx)(n.p,{children:"This command will automatically build the extension and copy it to the extension directory of the current PHP version."}),"\n",(0,i.jsxs)(n.ol,{start:"5",children:["\n",(0,i.jsx)(n.li,{children:"Test"}),"\n"]}),"\n",(0,i.jsxs)(n.p,{children:["use ",(0,i.jsx)(n.code,{children:"php -m"})," to check if the extension is installed successfully."]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"php -m | grep opendal-php\n"})}),"\n",(0,i.jsx)(n.p,{children:"Composer test:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"cd opendal/bindings/php\n\ncomposer install\ncomposer test\n"})}),"\n",(0,i.jsx)(n.h2,{id:"license-and-trademarks",children:"License and Trademarks"}),"\n",(0,i.jsxs)(n.p,{children:["Licensed under the Apache License, Version 2.0: ",(0,i.jsx)(n.a,{href:"http://www.apache.org/licenses/LICENSE-2.0",children:"http://www.apache.org/licenses/LICENSE-2.0"})]}),"\n",(0,i.jsx)(n.p,{children:"Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation."})]})}function a(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(o,{...e})}):o(e)}const p={title:"PHP \ud83d\udea7"},d=void 0,c={},h=[{value:"Example",id:"example",level:2},{value:"Requirements",id:"requirements",level:2},{value:"Install Extension",id:"install-extension",level:2},{value:"License and Trademarks",id:"license-and-trademarks",level:2}];function x(e){return(0,i.jsx)(r.A,{basePath:"bindings/php/",children:(0,i.jsx)(a,{components:{h1:"h2"}})})}function u(e={}){const{wrapper:n}={...(0,l.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(x,{...e})}):x()}},8699:(e,n,s)=>{s.d(n,{A:()=>l});var t=s(758),i=s(6070);function l(e){let{children:n,owner:s="apache",repo:l="opendal",branch:r="main",basePath:o="",components:a={}}=e;const p=e=>{const n=e.replace(/^\.\//,"");return`https://github.com/${s}/${l}/blob/${r}/${o}${n}`},d={...a,a:e=>{const{href:n,...s}=e;return n&&n.startsWith("./")?(0,i.jsx)("a",{...s,href:p(n)}):(0,i.jsx)("a",{...e})},p:e=>{const{children:n}=e;if("string"==typeof n){const e=/\[(.*?)\]:\s*(\.\/[^\s]+)/g;if(e.test(n)){const s=n.replace(e,((e,n,s)=>`[${n}]: ${p(s)}`));return(0,i.jsx)("p",{children:s})}}return(0,i.jsx)("p",{...e})}};return"string"==typeof n?(e=>{if("string"!=typeof e)return e;let n=e.replace(/\[(.*?)\]\((\.\/[^)]+)\)/g,((e,n,s)=>`[${n}](${p(s)})`));return n=n.replace(/\[(.*?)\]:\s*(\.\/[^\s]+)/g,((e,n,s)=>`[${n}]: ${p(s)}`)),n})(n):t.isValidElement(n)?t.cloneElement(n,{components:{...n.props.components||{},...d}}):n}},5658:(e,n,s)=>{s.d(n,{R:()=>r,x:()=>o});var t=s(758);const i={},l=t.createContext(i);function r(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); |