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

WebUI with php -S #201

Closed
cycle20 opened this issue Oct 15, 2022 · 16 comments
Closed

WebUI with php -S #201

cycle20 opened this issue Oct 15, 2022 · 16 comments

Comments

@cycle20
Copy link

cycle20 commented Oct 15, 2022

Hi,
Is it possible to serve the web-ui by php -S localhost:8000?
I would like to view reported data generated by command line script execution.
My config is:

php -i | grep spx
/etc/php/8.1/cli/conf.d/20-spx.ini,
spx.data_dir => /tmp/spx => /tmp/spx
spx.debug => 0 => 0
spx.http_enabled => 1 => 1
spx.http_ip_var => REMOTE_ADDR => REMOTE_ADDR
spx.http_ip_whitelist => 127.0.0.1 => 127.0.0.1
spx.http_key => dev => dev
spx.http_profiling_auto_start => no value => no value
spx.http_profiling_builtins => no value => no value
spx.http_profiling_depth => no value => no value
spx.http_profiling_enabled => no value => no value
spx.http_profiling_metrics => no value => no value
spx.http_profiling_sampling_period => no value => no value
spx.http_trusted_proxies => 127.0.0.1 => 127.0.0.1
spx.http_ui_assets_dir => /usr/share/misc/php-spx/assets/web-ui => /usr/share/misc/php-spx/assets/web-ui

I get HTTP status 404 for this request: http://localhost:8000/?SPX_KEY=dev&SPX_UI_URI=/
Thanks in advance,
Csongor

@AlexNDRmac
Copy link
Contributor

AlexNDRmac commented Oct 15, 2022

Hi @cycle20, yes, it possible. You need proper command.

First - you need to have a simple index.php file. Without this file I can't run successfully web-ui. So, create it in some place index.php with next contents:

<?php

phpinfo();

Next - use this command to run web-ui for specified directory

php -d spx.data_dir="./my-folder-with-spx-profiles/" -S localhost:8000 -t "full-path-to-folder-with-index-php/"

I'm personally using bash script to open saved profiles:

#!/usr/bin/env bash

help=$(cat << EOF
----------------------------------------------------------------
$(basename "$0") <path>

path:           Path to folder with PHP-SPX profiles

EOF
)

if [ -d "$1" ]; then
  data_dir=$1
else
  data_dir=$(dirname "$1")
fi

## Main

if [ $# -eq 0 ]; then
  >&2 echo "$(basename "$0"): Missing required argument."
  >&2 echo "$help"
  exit 1
fi

>&2 echo "-- Profiler Web-UI URI: http://localhost:8000/?SPX_KEY=dev&SPX_UI_URI=/"
php -d spx.data_dir="$data_dir" -S localhost:8000 -t "$(phpenv prefix)/www"

Usage - is simple as possible:

./spx-profiler-ui.sh ./my-folder-with-saved-profiles/

@verfriemelt-dot-org
Copy link

i have also issues getting this started properly:

 $  ls /tmp/spx
.rw-rw-rw-  635 easteregg easteregg 2022-10-16 10:45 spx-full-20221016_104524-nb1415-2580018-1804289383.json
.rw-r--r-- 433k easteregg easteregg 2022-10-16 10:45 spx-full-20221016_104524-nb1415-2580018-1804289383.txt.gz
 $  php -i | grep spx
spx.data_dir => /tmp/spx => /tmp/spx
spx.debug => 0 => 0
spx.http_enabled => 1 => 1
spx.http_ip_var => REMOTE_ADDR => REMOTE_ADDR
spx.http_ip_whitelist => 127.0.0.1 => 127.0.0.1
spx.http_key => dev => dev
spx.http_profiling_auto_start => no value => no value
spx.http_profiling_builtins => no value => no value
spx.http_profiling_depth => no value => no value
spx.http_profiling_enabled => no value => no value
spx.http_profiling_metrics => no value => no value
spx.http_profiling_sampling_period => no value => no value
spx.http_trusted_proxies => 127.0.0.1 => 127.0.0.1
spx.http_ui_assets_dir => > /usr/share/misc/php-spx/assets/web-ui => > /usr/share/misc/php-spx/assets/web-ui

and started via

SPX_REPORT=full SPX_ENABLED=1 PHP_CLI_SERVER_WORKERS= php -S localhost:8000 -t public

i get a 404 :(

@NoiseByNorthwest
Copy link
Owner

@verfriemelt-dot-org As @AlexNDRmac explained you need an URL targeting a real PHP script (even an empty script is fine for this purpose) within your public directory.

@verfriemelt-dot-org
Copy link

i did that 🤔

 $  stat public/index.php
  File: public/index.php
  Size: 296             Blocks: 8          IO Block: 4096   regular file
Device: 254,1   Inode: 17971337    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/easteregg)   Gid: ( 1000/easteregg)
Access: 2022-09-30 07:53:06.627132288 +0200
Modify: 2022-09-30 07:53:06.627132288 +0200
Change: 2022-09-30 07:53:06.627132288 +0200
 Birth: 2022-09-30 07:53:06.627132288 +0200

@NoiseByNorthwest
Copy link
Owner

But you ultimately get a 404 so something must be wrong with your setup or the URL you use.

@verfriemelt-dot-org
Copy link

i am requesting this:

http://localhost:8000/?SPX_KEY=dev&SPX_UI_URI=/

so pretty much the same setup as @cycle20 and i cannot find what i am missing :(

@AlexNDRmac
Copy link
Contributor

@verfriemelt-dot-org maybe smth with web-ui assets path. Double check if you have web-ui assets in /usr/share/misc/php-spx/assets/web-ui or provide the proper path.

Also, I would recommend to use fully qualified path for directory with index.php and change spx.http_ip_whitelist, spx.http_trusted_proxies values to '*'

@cycle20
Copy link
Author

cycle20 commented Oct 16, 2022

Hi @AlexNDRmac,
thank you for response. Unfortunately I got just a slightly better situation.
I got status code 200, but a message - not from the PHP engine - states: "File not found".
I don't know which file. :S How can I figure out which file is missing?
Thank you


NOTE: I tried spx.debug=1, but it didn't provide more details to me.

image

@AlexNDRmac
Copy link
Contributor

AlexNDRmac commented Oct 16, 2022

Ok :) Let's try with the clear state. Suppose - we does't have SPX - just default PHP in your OS.

What needs to be done:

  • Clone repository with SPX profiler (e.g.: ~/src/php-spx)
  • Build php-spx without install step, just - make

Now we have:

  • php without spx extension
  • built spx.so in ~/src/php-spx/modules/
  • web-ui in ~/src/php-spx/assets/web-ui

Ok - let's try to check if extension works:

cd ~/src/php-spx

## This command will print extension info.
php -d extension=./modules/spx.so --ri SPX

## output
SPX

SPX Support => enabled
SPX Version => 0.4.12
.....

Let's try to open web-ui (without configuration and installed extension):

cd ~/src/php-spx

## Create dir for profiles
mkdir ~/src/php-spx/profiles

## Create required index.php file
echo '<?php' > ~/src/php-spx/profiles/index.php

## Start web-ui
php -d extension=./modules/spx.so \
  -d spx.key=dev \
  -d spx.http_ui_assets_dir=~/src/php-spx/assets/web-ui \
  -d spx.data_dir=~/src/php-spx/profiles \
  -S localhost:8000 \
  -t ~/src/php-spx/profiles

## Open web-ui in default browser
open http://localhost:8000/?SPX_KEY=dev&SPX_UI_URI=/

If you already have profiles - just put it to specified spx.data_dir folder

Profit.

@NoiseByNorthwest
Copy link
Owner

I got status code 200, but a message - not from the PHP engine - states: "File not found".

It may be a broken SPX 404 response. In this case it is caused by a unfound UI asset file, is spx.http_ui_assets_dir properly configured ? And is the corresponding directory OK regarding its content ?

@verfriemelt-dot-org
Copy link

ah geeez, i had a typo in my php.ini :( sorry for wasting your time!

@cycle20
Copy link
Author

cycle20 commented Oct 18, 2022

Hi @AlexNDRmac ,
Thank you for the very detailed guideline.
I followed it, but I am not so lucky.
I also removed stuffs of previous intall (web assets from /usr/share... and so on)
I used this command line:

php -d extension=./modules/spx.so \
  -d spx.key=dev \
  -d spx.http_ui_assets_dir=/tmp/php-spx/assets/web-ui \
  -d spx.data_dir=/tmp/php-spx/profiles \
  -S localhost:8000 \
  -t /tmp/php-spx/profiles

index.php is located in the profiles directory.

Server log:

[Tue Oct 18 19:17:17 2022] PHP 8.1.11 Development Server (http://localhost:8000) started
[Tue Oct 18 19:17:26 2022] 127.0.0.1:38576 Accepted
[Tue Oct 18 19:17:26 2022] 127.0.0.1:38592 Accepted
[Tue Oct 18 19:17:26 2022] 127.0.0.1:38576 [200]: GET /?SPX_KEY=dev&SPX_UI_URI=/
[Tue Oct 18 19:17:26 2022] 127.0.0.1:38576 Closing
[Tue Oct 18 19:17:26 2022] 127.0.0.1:38592 [404]: GET /favicon.ico - No such file or directory
[Tue Oct 18 19:17:26 2022] 127.0.0.1:38592 Closing

This request loads only the blank index.php, it does not result the web ui. :(
Do I miss something? I have no clue.

Thank you,
Csongor

@AlexNDRmac
Copy link
Contributor

Try to add phpinfo() to index.php and see what's in SPX ini directives. Maybe spx.key is missing or different, maybe you have smth in whitelist. If so - try to redefine this param with cli command.

@cycle20
Copy link
Author

cycle20 commented Oct 18, 2022

Do you mean spx.http_key or spx.key?
The first one has no value, the second one is not listed in SPX table of phpinfo().

@cycle20
Copy link
Author

cycle20 commented Oct 18, 2022

Ok, it works. I also had to add to the command line-defined list of derectives: spx.http_key, spx.http_enabled, spx.http_ip_whitelist.
Thank you very much.

@cycle20 cycle20 closed this as completed Oct 18, 2022
@cycle20
Copy link
Author

cycle20 commented Oct 18, 2022

Final summary:

php -d extension=./modules/spx.so \
  -d spx.key=dev \
  -d spx.http_key=dev \
  -d spx.http_ip_whitelist=127.0.0.1 \
  -d spx.http_enabled=1 \
  -d spx.http_ui_assets_dir=/tmp/php-spx/assets/web-ui \
  -d spx.data_dir=/tmp/php-spx/profiles \
  -S localhost:8000 \
  -t /tmp/php-spx/profiles

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

No branches or pull requests

4 participants