3

After I got an issue with Jenkins, that the deployment is hanging up on jobs, that need to execute PHP on the command line (pdepend, phpmd, phpcpd etc.), and noticed, that I also cannot re-install Composer or run tools like PHPLoc on the command line, I created a PHP file

<?php
print_r(get_defined_constants());

and tried to execute it on the command line:

php phptest.php

And it didn't work. When I do so, nothing happens. No errors. Just nothing:

enter image description here

The environment is PHP 7.0.3 and Ubuntu 14.04.3 (in a VirtualBox VM). Btw. php -v or php -i executed on the command line is still working.

What might cause this issue and how to solve it?

EDIT

The permissions seem to be correct:

root@ubuntuvm:~/Desktop# ls -lia | grep "phptest.php"
132234 -rw-r--r--  1 root root   40 Aug  2 17:29 phptest.php

777 is also not working:

root@ubuntuvm:~/Desktop# chmod 777 ./phptest.php 
root@ubuntuvm:~/Desktop# php phptest.php
^C

The error reporting is set up:

/etc/php/7.0/cli

error_reporting = E_ALL
display_errors = On
log_errors = On
error_log = /var/log/php_errors.log
automatix
  • 14,018
  • 26
  • 105
  • 230
  • Is there no output at all? Does the script hang or does it complete execution with no output? – DrRoach Aug 02 '17 at 16:19
  • The script hangs up and doesn't complete the execution. There is no output, just a line break (made by the OS -- so absolutely no output generated by the PHP script). See the screenshot, I've just added to the question. – automatix Aug 02 '17 at 16:23
  • That's weird. Are the permissions for your php file correct? Is it locked to just the www-data user? Also are the permissions correct? Usually 644 (rw-rw-r--) – DrRoach Aug 02 '17 at 16:26
  • PHP is throwing an error, but error output is disabled. So appears like nothing is happening. Check your PHP logs or update your PHP.ini to output errors. – Reactgular Aug 02 '17 at 16:29
  • @ThinkingMedia is probably right!! Check the logs or add: `error_reporting(E_ALL);` `ini_set("display_errors", 1);` To your code – DrRoach Aug 02 '17 at 16:30
  • @DrRoach Yes, the permissions seem to be OK. See the update above. – automatix Aug 02 '17 at 16:36
  • @ThinkingMedia The error reporintg is set up, see the update above. – automatix Aug 02 '17 at 16:38
  • Hmm, can you run the script with `sudo`? – DrRoach Aug 02 '17 at 16:38
  • @automatix if there are no errors, then maybe nothing is wrong. Try adding echo statements before and after the `print_r` as it might be outputting an empty string. – Reactgular Aug 02 '17 at 16:38
  • @DrRoach I'm `root` on the system (it's a local VM). – automatix Aug 02 '17 at 16:40
  • @ThinkingMedia I tried `print_r(get_defined_constants());` (see the question) and also things like `die('###')`. If everything is correct, such scripts must generate an output. – automatix Aug 02 '17 at 16:43
  • Make sure the PHP file is not unicode with a unicode prefix byte. – Reactgular Aug 02 '17 at 17:19
  • Does the command work if you run PHP in interactive mode? `php -a` – Reactgular Aug 02 '17 at 17:20
  • Try the file option as well. `php -f ` – Reactgular Aug 02 '17 at 17:21
  • Try this: `php -n -r "print_r(get_defined_constants());"` and I'm running out of ideas. lol – Reactgular Aug 02 '17 at 17:23
  • @ThinkingMedia Yes, the interactive mode is working. – automatix Aug 02 '17 at 19:27
  • 1
    Everything is working again! I really have not changed anything at the system! Just restarted the VM. I have no idea, why it's working now... I simply installed another VM and the old one got another IP. But that's all -- and it cannot affect the behavior of PHP!.. – automatix Aug 02 '17 at 19:33
  • @automatix this is obviously Microsoft's fault and a Windows problem. lol – Reactgular Aug 02 '17 at 20:26
  • 1
    @ThinkingMedia Exactly -- a Microsoft's fault and a Windows problem on a Linux VM... :) – automatix Aug 03 '17 at 09:55
  • This is happening to me now. :( What the hell is going on?! I even just made a one line php that just has `print "wtf\n";` and when I try to run that from the command line it just hangs. – Kenny Wyland Dec 11 '18 at 21:01

1 Answers1

11

This just started happening to me and I finally figured it out. I don't know if this was your problem or if you can replicate it, but hopefully this may help somebody else.

I had two projects open in PHPStorm and in one of those projects I had turned on "Listen for PHP Debug Connections" and due to some configuration option, as soon as I ran ANY php script anywhere on my system, that one PHPStorm window would grab the process and halt it for debugging.

enter image description here

Normally, this would cause PHPStorm to jump forward to be the top-most window to give me a visual cue that it can taken control, but due to the type of script I was running I was immediately switching windows after starting it. So my manual window switching made me not notice PHPStorm's auto-switch.

After making PHPStorm stop listening for connections, I was able to run scripts again.

Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229