Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide PHP normal wasm build #121

Open
liudonghua123 opened this issue Nov 15, 2023 · 3 comments
Open

Provide PHP normal wasm build #121

liudonghua123 opened this issue Nov 15, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@liudonghua123
Copy link

Is your feature request related to a problem? Please describe.

Hi, I tried the wasm build of python, ruby and php with my wasmer runtime, python and ruby are good, but the PHP only provide wasmedge version which could not run under the latest wasmer v4.2.3.

> wasmer python-3.11.4.wasm --dir . hello.py
Hello World

> wasmer ruby-3.2.2.wasm --dir . hello.rb
Hello World

> wasmer php-cgi-8.2.6.wasm --dir . hello.php
Status: 404 Not Found
X-Powered-By: PHP/8.2.6
Content-type: text/html; charset=UTF-8

No input file specified.

> wasmer php-8.2.6-wasmedge.wasm --dir . hello.php
error: Instantiation failed
╰─▶ 1: Error while importing "wasi_snapshot_preview1"."sock_open": unknown import. Expected Function(FunctionType { params: [I32, I32, I32], results: [I32] })

> wasmedge.exe --dir . php-8.2.6-wasmedge.wasm hello.php
Hello World
> 

Can we build the normal or general PHP wasm?

Describe the solution you'd like

Build normal or general PHP wasm like python and ruby.

Describe alternatives you've considered

N.A.

Additional context

N.A.

@assambar
Copy link
Contributor

assambar commented Nov 16, 2023

The php-cgi CLI will need the -f option before the filename. This should work.

wasmer php-cgi-8.2.6.wasm --dir . -f hello.php

We only offer the full PHP interpreter flavored for WasmEdge as we've based it's socket implementation on top of WasmEdge sockets. We did not find it useful (at this time) to invest into cutting all the socket-related code from the php CLI and offering a version with that. php-cgi seemed enough for most use-cases, as it is what runs in most traditional deployments.

Let me know if the above line fixes your use-case. If that's so I would close the issue for now.

@liudonghua123
Copy link
Author

@assambar Thanks, now I see some difference about php-cgi and php.

I tried wasmer php-cgi-8.2.6.wasm --dir . -f hello.php, but it did not work for me, I still could not use wasmer/wasmedge php-cgi to run an echo hellworld example.

Did I miss something? It seemed I could not pass hello.php to php-cgi.

And another question, why php cli needs socket while php-cgi does not?

> wasmer run php-cgi-8.2.6.wasm --dir . -- -f hello.php             
No input file specified.

> wasmedge run --dir . php-cgi-8.2.6.wasm -- -f hello.php           
Status: 404 Not Found
X-Powered-By: PHP/8.2.6
Content-type: text/html; charset=UTF-8

No input file specified.

> wasmedge run --dir . php-cgi-8.2.6.wasm -- hello.php              
X-Powered-By: PHP/8.2.6
Content-type: text/html; charset=UTF-8


> wasmer run php-cgi-8.2.6.wasm --dir . -- -h                       
Usage: php-cgi [-q] [-h] [-s] [-v] [-i] [-f <file>]
       php-cgi <file> [args...]
  -a               Run interactively
  -b <address:port>|<port> Bind Path for external FASTCGI Server mode
  -C               Do not chdir to the script's directory
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse <file>.  Implies `-q'
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -q               Quiet-mode.  Suppress HTTP Header output.
  -s               Display colour syntax highlighted source.
  -v               Version number
  -w               Display source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.
  -T <count>       Measure execution time of script repeated <count> times.

> 
> php hello.php                                                     
Hello World
> php-cgi hello.php                                                 
X-Powered-By: PHP/8.2.12
Content-type: text/html; charset=UTF-8

Hello World
> php-cgi not-exists.php                                              in cmd at 22:48:32
Status: 404 Not Found
X-Powered-By: PHP/8.2.12
Content-type: text/html; charset=UTF-8

No input file specified.

> php-cgi -h                                                        
Usage: php-cgi [-q] [-h] [-s] [-v] [-i] [-f <file>]
       php-cgi <file> [args...]
  -a               Run interactively
  -b <address:port>|<port> Bind Path for external FASTCGI Server mode
  -C               Do not chdir to the script's directory
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse <file>.  Implies `-q'
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -q               Quiet-mode.  Suppress HTTP Header output.
  -s               Display colour syntax highlighted source.
  -v               Version number
  -w               Display source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.
  -T <count>       Measure execution time of script repeated <count> times.

> 

@liudonghua123
Copy link
Author

liudonghua123 commented Nov 16, 2023

It's really strange, I can pass the file to python-3.11.4.wasm. But the same method did not work for php-cgi-8.2.6.wasm.

I can use pipe stdin to make it work.

> wasmer run --dir . python-3.11.4.wasm hello.py
Hello World

> wasmer run --dir . php-cgi-8.2.6.wasm hello.php
Status: 404 Not Found
X-Powered-By: PHP/8.2.6
Content-type: text/html; charset=UTF-8

No input file specified.

> cat hello.php | wasmer run --dir . php-cgi-8.2.6.wasm
X-Powered-By: PHP/8.2.6
Content-type: text/html; charset=UTF-8

Hello World
> cat hello.php | php-cgi
X-Powered-By: PHP/8.2.12
Content-type: text/html; charset=UTF-8

Hello World
> php-cgi hello.php
X-Powered-By: PHP/8.2.12
Content-type: text/html; charset=UTF-8

Hello World
> cat hello.py | python
Hello World
> cat hello.py | wasmer run --dir . python-3.11.4.wasm
⠁ Initializing the WebAssembly VM
⠁ Loading from "python-3.11.4.wasm"
⠁ Compiling to WebAssembly
⠉ Compiling to WebAssembly
Python 3.11.4 (tags/v3.11.4:d2340ef, Jul 14 2023, 11:21:53) [Clang 16.0.0 ] on wasi
Type "help", "copyright", "credits" or "license" for more information.
>>> Hello World
>>>

>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants