I'm trying to use vld to view opcode of a php file
prep
I've installed vld with:
pecl install channel://pecl.php.net/vld-0.12.0
To get familiar with VLD, I'm trying to compare to php files (echo1 and echo2)
echo1.php
<?php
echo "Hello"." "."World";
echo2.php
<?php
echo "Hello"," ","World";
phpinfo() shows that vld seems to be enabled:
vld support enabled
Directive Local Value Master Value
vld.active 0 0
vld.col_sep
vld.dump_paths 1 1
vld.execute 1 1
vld.format 0 0
vld.save_dir /tmp /tmp
vld.save_paths 0 0
vld.skip_append 0 0
vld.skip_prepend 0 0
vld.verbosity 1 1
problem
running php files shows output instead of opcode
# php -dvld.active=1 -f echo1.php
Hello World
# php -dvld.active=1 -dvld.execute=0 -f echo1.php
Hello World
# php -dvld.active=1 -f echo2.php
Hello World
# php -dvld.active=1 -dvld.execute=0 -f echo2.php
Hello World
Obviously I'm missing something :)
versions running
php version
# php -v
PHP 5.4.4-14+deb7u14 (cli) (built: Aug 21 2014 08:36:44)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
Running Debian in Virtualbox with Apache 2.2.22
After updating to PHP 5.6.2 I gave it another go and it is running :)
php version
# php -v
PHP 5.6.2 (cli) (built: Oct 17 2014 07:22:10)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
install pear
yum install php56w-pear
installing vld
pecl install vld
add extension to /etc/php.ini (or in file in /etc/php.d/__.ini)
#/etc/php.d/vld.ini
extension=vld.so
restart httpd service and test again (fingers crossed)
# php -dvld.active=1 -f echo1.php
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename: /var/www/html/echo1.php
function name: (null)
number of ops: 4
compiled vars: none
line #* E I O op fetch ext return operands
-------------------------------------------------------------------------------------
2 0 E > CONCAT ~0 'Hello', '+'
1 CONCAT ~1 ~0, 'World'
2 ECHO ~1
3 3 > RETURN 1
branch: # 0; line: 2- 3; sop: 0; eop: 3; out1: -2
path #1: 0,
Hello World
Boom Baby!
I don't know why, but it is working as expected :)
Now the OPCODE adventures can begin (also a love story)
You might be add extension.so to wrong php.ini file
You might be add the extension to php.ini that use by your webserver instead of cli version
What you can do is run locate php.ini, and choose the cli version of php.ini and add extension.so to that file
Normally cli version of php.ini located at /etc/php5/cli/php.ini
Dont forget to restart your console too
Related
I've installed PHP on my windows 10 computer, and started IIS.
But when I browse to http://localhost/phpinfo.hml the page is completely blank.
And if I look at the file view in IIS, it seems that it's not aware that the file exists.
I've verified that the phpinfo.html file is in the right place:
ls -l C:\inetpub\wwwroot\phpinfo.html
Directory: C:\inetpub\wwwroot
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 7/16/2020 8:54 AM 72 phpinfo.html
And has the right contents:
PS C:\inetpub\wwwroot> cat .\phpinfo.html
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
PHP is installed:
php --version
PHP 7.4.1 (cli) (built: Dec 17 2019 19:23:59) ( NTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
I gave my windows user full access to that directory. What am I doing wrong? How can I get this working?
If you want to show phpinfo page, you need to change phpinfo.html to phpinfo.php.
And you also need to handle PHP requests by using IIS Manager, you can set this in Handler Mappings.
More information about how to configure IIS to Handle PHP Requests you can refer to this link: Configure IIS to Handle PHP Requests
this my /usr/local/ folder
this my php version showing`
PHP -v
PHP 5.5.38 (cli) (built: Mar 30 2017 12:11:07)
Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0,
Copyright (c) 1998-2015 Zend Technologies`
this is my PATH
echo $PATH
/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
What i want to do is switch to my php72 folder so when i type php -v to show me php 7.2
I have searched a lot and tryed many solutions but it is not working.
any help would be appreciated
Go in the Finder and press ⌘⌥P to turn on the display of the path at the bottom of the screen - no idea why Apple leaves this turned off (rant over).
Now navigate to /usr/local/php5-7.2ORC.... and navigate around in there till you find the executable called php. Note the path at the bottom of the screen when you have that file selected. Remove the word php from the right end of that path, now set your PATH like this:
export PATH=<WHATEVER-YOU_GOT_ABOVE>:$PATH
In essence, you will end up doing something like:
export PATH=/usr/local/php5-7.20ORC.../bin:$PATH
I need to use a php script without "php" command.
For example:
$ ./test.php
Permissions are sets to 755.
This is the script
#!/usr/bin/php -q
<?php
echo "hello world";
?>
/usr/bin/php -v (so path exists)
returns
PHP 7.0.15-1+deb.sury.org~xenial+1 (cli) (built: Jan 20 2017 08:53:13) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.15-1+deb.sury.org~xenial+1, Copyright (c) 1999-2017, by Zend Technologies
This is the error I'll get everytime:
Exception: Zend Extension ./test.php does not exist
Also calling script with fullpath I'll get same error.
Calling this it works properly
$ php ./test.php
Any idea?
NOTE: The author found the solution and put it up in the comments but never posted an actual answer, so this answer is just clarifying what the author already said above so as to make the answer more obvious.
I was also getting the Exception: Zend Extension does not exist when I was trying to pipe an email via cpanel forwarder into a php script.
I opened the file in my editor (Komodo Edit on Windows) and went to EDIT > CURRENT FILE PREFERENCES and noticed that LINE ENCODINGS was set to DOS/Windows (\r\n)
I changed the LINE ENCODING to UNIX (\n) and saved it and re-uploded it and the error went away and all is good now.
Obviously the steps will vary depending on what editor you use, but the solution is to make sure your Line Encodings are UNIX and not DOS/Windows.
Just run dos2unix on the file
# ./database.php
Exception: Zend Extension ./database.php does not exist
# apt install dos2unix
# dos2unix database.php
dos2unix: converting file database.php to Unix format...
# ./database.php
Yeah!!! It work's!!!!
I'm trying to understand more deep and php internals by just executing native php functions against to my implementations.
But in every opcode dump I see these two following opcodes :
EXT_NOP : http://php.net/manual/tr/internals2.opcodes.ext-nop.php
EXT_STMT : http://php.net/manual/tr/internals2.opcodes.ext-stmt.php
as you see in docs there is no detailed explanation.
Even in following example which given in the doc my dumps are different than the doc's spesification. I really want to know why are these two stands in every dump ? What is their functionality ?
<?php
/*
* no operation
* opcode number: 0
*/
function A(){};
?>
Env Spesification :
LXC
Linux web 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u5 (2015-10-09) x86_64 GNU/Linux
PHP 5.6.15-1~dotdeb+7.1 (cli) (built: Nov 3 2015 16:29:58)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans
OpCode Dump :
➜ php -d vld.active=1 -d vld.execute=0 -f nop.php
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename: /root/web/www/optest/nop.php
function name: (null)
number of ops: 5
compiled vars: none
line #* E I O op fetch ext return operands
-------------------------------------------------------------------------------------
2 0 E > EXT_STMT
1 NOP
2 NOP
4 3 EXT_STMT
4 > RETURN 1
branch: # 0; line: 2- 4; sop: 0; eop: 4; out1: -2
path #1: 0,
Function a:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename: /root/web/www/optest/nop.php
function name: A
number of ops: 3
compiled vars: none
line #* E I O op fetch ext return operands
-------------------------------------------------------------------------------------
2 0 E > EXT_NOP
1 EXT_STMT
2 > RETURN null
branch: # 0; line: 2- 2; sop: 0; eop: 2; out1: -2
path #1: 0,
End of function a
EXT_NOP is used in the cases where previously there was something to do (ie a function declaration), but the engine has internally already taken care of this, and replaced the original opcode with EXT_NOP. NOP stands for "no operation". NOP is slightly different from EXT_NOP, as it's generated at different times, but it does the same thing: Nothing.
EXT_STMT is created in between statements, and allows debuggers (such as Xdebug) to stop in safe locations. Xdebug uses a "statement handler" (https://github.com/derickr/xdebug/blob/master/xdebug.c#L2534) to hook into the Zend Engine. The Zend Engine calls this handler for each EXT_STMT opcode it encounters.
I have two servers. They are both running php 5.3.3. This code works on one server and returns a syntax error on the other. Is there a php ini setting that affects this behaviour? I can't find anything related in the PHP documentation, but I may be looking in the wrong place.
Server 1
> php -v
PHP 5.3.3 (cli) (built: Sep 23 2010 14:15:16)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.0.3, Copyright (c) 2002-2007, by Derick Rethans
php > echo explode(" ", " foo ")[1];
foo
Server 2
> php -v
PHP 5.3.3 (cli) (built: Jan 31 2011 15:57:29)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
php > echo explode(" ", " foo ")[1];
Parse error: syntax error, unexpected '[', expecting ',' or ';' in php shell code on line 1
Another idea: PHP on both servers is custom-compiled, so it could also be a different compile flag.
No.
PHP doesn't support this syntax. It's on the trunk, but not yet released (as of PHP 5.3.3).
I have no idea how it's working on your first server, but perhaps this "Xdebug" is making a difference?
Aha! I figured it out.
We installed Facebook's XHP to profile our development server. This syntax (which is quite elegant) was added in in the PHP module. Here's a diff of the php.ini file between server 1 and 2:
> ; XHP https://github.com/facebook/xhp/wiki/Building-XHP
> extension=xhp.so
> ; adds support for the [] operator on the return value of a function
> xhp.idx_expr = 1
> ; Tracking errors in XHP applications is very difficult without annotations.
> xhp.include_debug = 1
I like this syntax, so I'll probably install XHP on the other server. Thanks for the help Michas for suggesting I diff the ini files.