-
-
Notifications
You must be signed in to change notification settings - Fork 302
feat: '-r' option for php-cli #1482
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
Conversation
As expected mac/arm currently fails the sanity check https://github.com/dunglas/frankenphp/actions/runs/14283719364/job/40036289078?pr=1482 |
I wonder if it would make sense to just enter the cli sapi if argv[0] is Edit: Or actually, if it is just |
Yeah I thought of that too, though I'm not sure what would be the best way to do this, maybe by somehow exposing the main function directly in php-src? |
@@ -19,13 +19,13 @@ func init() { | |||
Long: ` | |||
Executes a PHP script similarly to the CLI SAPI.`, | |||
CobraFunc: func(cmd *cobra.Command) { | |||
cmd.DisableFlagParsing = true | |||
cmd.Flags().StringP("code", "r", "", "Execute PHP code directly without <php ... ?> tags") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<?php
you mean
Nvm mac sanity check was failing due to a typo 😅 |
Or just copy-paste, er, vendor it. |
@AlliBalliBaba any chance you can verify that the |
Sadly, I don't have a mac either, but I can try asking a colleague tomorrow. |
Hey! It’s a bit of a ninja patchwork, but it gets the job done for now 😄 #!/usr/bin/env bash
args=("$@")
index=0
filename=
for i in "$@"
do
if [ "$i" == "-d" ]; then
unset 'args[$index]'
unset 'args[$index+1]'
fi
if [ "$i" == "-r" ]; then
filename=$(cat /proc/sys/kernel/random/uuid).temp.php
echo "<?php ${args[$((index+1))]} ?>" | tee "$filename" > /dev/null
unset 'args[$index]'
unset 'args[$index+1]'
args=("$filename")
break
fi
index=$((index+1))
done
/usr/bin/frankenphp php-cli ${args[@]}
if [ -n "$filename" ]; then
rm -f "$filename"
echo
fi
Thank you @Lolozendev for your help |
Can we merge this one @AlliBalliBaba? |
Yeah I think so 👍 . Just forwarding the input to php-cli is something for a different PR |
This PR adds the -r option for directly executing code with php-cli
frankenphp php-cli -r "echo 'Hello world'";
This can be useful in some situations where PHP is not directly installed on the system, but some library setup code uses the
-r
flagThe main reason I'm adding this option though is to have another sanity check for the static binaries after compilation.