EDIT: As the comment below by Bacon Bits suggests, I needed to save as UTF8
I'm trying to execute any php script in Powershell on windows 10.
Looks like it's eating the "<" of the script and then treating the file as a normal file.
sample php script:
<?php
echo "why?";
?>
Result of running script:
C:\php\php .\test.php
? p h p
e c h o " w h y ? " ;
? >
Version information:
C:\php\php -v
PHP 7.3.5 (cli) (built: May 1 2019 13:16:56) ( NTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies
I was running the cgi version earlier with nginx and it seemed to work fine in that context.
Related
Suppose there are leading zeros in IPv4 address representation such as 012.012.012.012.
To suppress the leading zeros, I simply write the following code, and it works as I expected on my Mac:
% php -r 'var_dump(long2ip(ip2long("012.012.012.012")));'
Command line code:1:
string(11) "12.12.12.12"
% php --version
PHP 7.3.25 (cli) (built: Dec 25 2020 22:03:38) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.25, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.25, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v3.0.1, Copyright (c) 2002-2020, by Derick Rethans
But this simple piece of code doesn't work on CentOS 7, it seems like ip2long("012.012.012.012") returns false value:
$ php -r 'var_dump(long2ip(ip2long("012.012.012.012")));'
string(7) "0.0.0.0"
$ php --version
PHP 7.3.25 (cli) (built: Nov 24 2020 11:10:55) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.25, Copyright (c) 1998-2018 Zend Technologies
$ cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
Both PHP versions are identical and I would expect them to return exact same values. I also read the ip2long docs and tried to find if there is any special options/configurations for this behaviour, but no luck.
Could someone lead me in the right direction?
What makes them different? And what should I do?
OK, I found the culprit. Different implementation of inet_pton(3) between LLVM and GCC leads this behaviour, as Russ-san commented. There was a bug report about the exact same problem 6 years ago. It seems PHP v5.2.10 had started using inet_pton instead of inet_addr according to this patch, that's why older versions of PHP treat each chunks as octal.
test.c
#include <stdio.h>
#include <arpa/inet.h>
#define INADDR "012.012.012.012"
int main() {
struct in_addr inaddr;
if (inet_pton(AF_INET, INADDR, &inaddr) == 0) {
printf("Invalid: %s\n", INADDR);
}
else {
printf("Valid: %s\n", INADDR);
}
return 0;
}
Mac
% cc test.cc && ./a.out
Valid: 012.012.012.012
Linux
$ cc test.cc && ./a.out
Invalid: 012.012.012.012
I gave up using ip2long / long2ip built-in functions and now trying to use https://github.com/mlocati/ip-lib
>>> \IPLib\Address\IPv4::fromString("1.2.3.12")->toString(true);
=> "001.002.003.012"
>>> \IPLib\Address\IPv4::fromString("001.002.003.012")->toString();
=> "1.2.3.12"
No problems so far.
I am doing "which php" in my mac book and its giving me the output as below :-
/usr/bin/php
While in path variable its showing me :-
~ manishk$ echo $PATH
/Applications/XAMPP/xamppfiles/bin/php-5.6.24:/usr/local/rvm/gems/ruby-2.1.2/bin:
Which php should point to php-5.6.24 .
Even php --version is giving me
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
I don't know where to set it to correct it .
The $PATH variable is ment as a list of directories, where your command binaries can be found. So, you have to add the directory where the php binary is located.
For XAMPP this means, you'll have to add the following path to your $PATH variable:
/Applications/XAMPP/bin
As this is a symlink to xamppfiles/bin, you can also use this one:
/Applications/XAMPP/xamppfiles/bin
I'm using XAMPP and PHP CLI to test my PHP script locally. The problematic line (the line 98) in db.php is:
$this->mysqli = new mysqli($host, $user, $pass, $dbname, $port);
And the error is:
No such file or directory in /path/to/my/file/db.php on line 98
This problem only appears when I execute a PHP file that requires db.php in Terminal. It works fine when I run it in browser. How come?
The CLI command I use is:
php test.php
Well, that's a very simple command. Is there anything I missed?
Note: I'm using Mac OS X 10.10.1
PHP version:
PHP 5.5.14 (cli) (built: Sep 9 2014 19:09:25)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
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
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.