4

the problem is in the following:

echo 'Hello...';

die('I died...');

echo 'HAHAHA!!!';

on the web browser it is executing the echo after the die(). on the CLI stops on the die() and does not shows the echo as expected.

My Specs: PHP 7.4 (FPM) web server Nginx (also tried with apache with the same result)

Also I had a time long a test server on windows and it was exiting the script when exit or die was called, but somehow on the debian test server is not doing that.

is there something I am missing? do you guys have any tip?

Thanks in advance....

Update on 2022-07-27 :

script: enter image description here

Browser output: enter image description here

CLI output enter image description here

I've updated the PHP version (same happening): enter image description here

@MarkusZeller yes is disabled the opcache: enter image description here

still not working... but somehow on the windows server under php7.4.26 runs the script with the expected die

The development environment is windows with Debian 11 (WSL2) I have also tried it yesterday on a test machine I have in my home with base Debian 11 installed and it has the same issue. Same thing with the Debian 11 test server at work.

@YourCommonSense the script is the same. Here is the nginx path config: enter image description here

deceze
  • 510,633
  • 85
  • 743
  • 889
ASCrespo
  • 79
  • 7
  • welcome to stackoverflow. i think this case strictly related to php fpm (fast cgi), so.. please add [tag:fpm] tag. – Bagus Tesa Jul 26 '22 at 12:09
  • I just tested this on the cli and the browser and in both cases the output I got was "Hello...I died...". – raphael75 Jul 26 '22 at 12:13
  • Did you enable pre-loading or opcache? – Markus Zeller Jul 26 '22 at 12:14
  • also, have you checked [how to stop php script execution on php-fpm](https://stackoverflow.com/questions/33955497/how-to-stop-php-script-execution-on-php-fpm-nginx)? – Bagus Tesa Jul 26 '22 at 12:15
  • @raphael75 : That was what i wanted to have... but somehow in the browser does not goes out – ASCrespo Jul 26 '22 at 12:20
  • @BagusTesa i will check the link – ASCrespo Jul 26 '22 at 12:20
  • tried same on w3school php editor and output is "Hello...I died..." – Aqib Javed Jul 26 '22 at 12:22
  • @MarkusZeller the opcache is off – ASCrespo Jul 26 '22 at 12:22
  • I just do not understand. I never had this problem.... But somehow with 'return' does what I want... Just a bit strange that the die() or exit is not doing it. I was thinking at first it was a problem in my development environment... But after Installing a fresh system it came the same out – ASCrespo Jul 26 '22 at 14:20
  • Can't you just upgrade to 8.1? 7.4 is quite old. – Markus Zeller Jul 26 '22 at 15:49
  • `die` / `exit` is a language construct - it _cannot_ fail. Either you have a typo or PHP is not executed at all. – Honk der Hase Jul 26 '22 at 18:11
  • @Honk der Hase that is what i was thinking from the beginning.... first time happening something like this... i can also do a screen share so you can check (in discord if you want to see)... i replicated the same thing now on my personal machine (before was only on my company laptop and in the new test server environment) – ASCrespo Jul 26 '22 at 20:40
  • @Markus Zeller I am going to try now with a diferent version ... the problem is that due to some libs i can not apply that to the company project. but the strange is that on the windows server it runs perfectly with 7.4 (somehow). – ASCrespo Jul 26 '22 at 20:42
  • Obviously, it is not "die()" but some other issue. You can wrap the die() call in some debugging output, like echo "before die"; and see. there won't be this "before die" either. As you are simply calling a different script in your browser – Your Common Sense Jul 27 '22 at 10:12
  • @YourCommonSense Thanks for the comment but, the problem is even the die being there the script continue to run .... somehow on the terminal it stops there but in the browser not. – ASCrespo Jul 27 '22 at 10:36
  • @YourCommonSense I have updated the post with the image from the nginx vhost configuration.... Like this you can see that is the same script... and what is happening in this dev environment is also happening in the test server I only saw that after the migration from windows to linux... – ASCrespo Jul 27 '22 at 10:52
  • if you look at **your own screenshot** it is not die. **There is no output from die**, nowhere that "I died" can be seen. Which means that die weren't called at all. And not your "keeps running after die". – Your Common Sense Jul 27 '22 at 12:07
  • You are using a framework. I think that's overloading die(). – Markus Zeller Jul 27 '22 at 12:12
  • @MarkusZeller Actually not we use some php requirements through composer but the base is not a framework. but in this example I am only loading a simple 3 line script nothing more. my only problem to know why the cli makes the expected and the browser output not. – ASCrespo Jul 27 '22 at 12:27
  • @YourCommonSense I really do not know what you want to achieve with the comment but open your eyes and see what is in the post. I would not be here posting if I didn't run into this. the example is there and the 2 runs (CLI and nginx with php-fpm). – ASCrespo Jul 27 '22 at 12:31
  • Yes sir! Did what you said! Opened my eyes and looked at your post! I see `Hello...HAHAHA!!!` without any `I died...` in sight! – Your Common Sense Jul 27 '22 at 12:35
  • Have you tried calling just `die()`? The only *possible* stab into the dark that comes to mind is that php-fpm *somehow* doesn't die when using a non-numeric "exit code". I know it's far-fetched, but… – deceze Jul 27 '22 at 12:35
  • @YourCommonSense Which means the `die` statement got skipped somehow/it did not output anything and also didn't die. Which is the perplexing behaviour OP is asking about here. *Assuming* this sample actually works as stated and OP isn't accidentally executing the wrong code… – deceze Jul 27 '22 at 12:37
  • @deceze not at all. what the OP is asking is why die, **albeit called**, doesn't stop the execution, whereas the situation is completely different: evidently, die isn't called at all. – Your Common Sense Jul 27 '22 at 12:38
  • @YourCommonSense *IF*, and that's a big *IF*, there's some bug that would cause `die` to not die, and in the process of not dying also to not output the message, that would explain the behaviour OP is observing. That it's happening only in a specific environment further supports this. – deceze Jul 27 '22 at 12:42
  • Something like this vaguely points in the same direction: https://bugs.php.net/bug.php?id=79948 – deceze Jul 27 '22 at 12:46
  • Another vaguely related issue: https://bugs.php.net/bug.php?id=79003 – deceze Jul 27 '22 at 12:51
  • @deceze I am a simple man and follow the ol' Hanlon's guidance: as long as there is no good evidence, assume the human factor, not a malicious bug. – Your Common Sense Jul 27 '22 at 12:55
  • @YourCommonSense Sure, but assuming OP isn't a complete moron and the presented evidence is real, that's convincing enough to start looking for PHP bugs. – deceze Jul 27 '22 at 12:56
  • @deceze thanks for the links... I was loking also in the bug tracker but only found one with a connection with opcache... at one point didn't pass to my situation because I have it disabled. But never less as I wrote earlier this situation did not happen on a windows based server only difference is the PHP version (earlier version to be more precise 7.4.26, in this example I tried with 7.4.30 and 8.1). – ASCrespo Jul 27 '22 at 13:12
  • 1
    I have found the problem... I removed all PHP extensions and installed only some of them after that the die / exit was not ignored anymore. I thank you all for the time you gave here... I am going to install every extension individually again and when I get the same error I will edit the post to write which extension was causing that problem... cya guys – ASCrespo Jul 27 '22 at 18:52

1 Answers1

3

Solution:

The cause of the problem was on the extension php-uopz. After installing every extension individually and testing after every install, the behavior only happens after this extension is activated. Hope this helps in case anyone runs into the same issue.

ASCrespo
  • 79
  • 7