die() is not stopping code from executing - php

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:
Browser output:
CLI output
I've updated the PHP version (same happening):
#MarkusZeller yes is disabled the opcache:
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:

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.

Related

Is opcache_reset supposed to work on windows?

Enviroment wamp on windows, PHP version 7.4
The result of opcache_get_status after calling opcode_reset shows
opcache_enabled => false
restart_pending => 1
This goes on for a long time and no actual restart is happening, and the manual restart count still shows 0.
Is this a specific windows gotcha thing, or I should look for some misconfiguration (where?)
I set up a WSL2 enviroment on the same machine and opcache_reset behaves as expected, so it must be just another way in which php behaves differently on linux and windows.

PHP is not working on Windows after I completely installed it

I am trying to setup php 5.5.12 on my Windows server 2008 R2
I found this good tutorial that walks you step by step
http://www.youtube.com/watch?v=WUoqkPJEp4Y
After completing every step everything seems to be fine.
I created a file called phpinfo.php and put the following code into and placed it on c:/inetpub/wwwroot
<?php php_info(); ?>
But when I got localhost/phpinfo.php or http://127.0.0.1:80/phpinfo.php I get a 404 error. I do not know why it is not working. when I execute the following from commands from the command line it looks like it is working and I get many output with no error.
cd c:/php
php -i
In addition to the instruction, I added the following to the registry of windows
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\PHP]
"IniFilePath"="C:\\PHP"
Can someone tell me what else do I need to make get php up and running on windows?
This is what is using port 80 on my server
To use localhost or 127.0.0.1 you need apache installed on your system too.
You can download xampp or wamp they both come with PHP, MySql & Apache installed in them.

PHP-cgi stops working randomly without error log

I'm using nginx with (WT-NMP - portable mysql nginx php app.). Everything is working perfectly except php-cgi, it is stopping randomly and i have to start it again, in fact i realized that if i add to post my website quickly (in wordpress), it is definitely stopping. But sometimes it is stopping without for no reason, maybe there is a reason but i cant see because no error shows in errorlogs.
I searched on the internet and I found something about my problem but I couldn't use these methods on my windows server.
The solution I found: SET PHP_FCGI_MAX_REQUESTS=0 to the script that starts php-cgi.exe
#ECHO OFF
ECHO Starting PHP FastCGI...
SET PHP_FCGI_MAX_REQUESTS=0
SET PATH="D:\Program Files\php;%PATH%"
"C:\Program Files\php\php-cgi.exe" -b 127.0.0.1:9000 -c "C:\Program Files\php\php.ini"
Any idea about my problem? or any idea how to use this codes on my windows server. I searched for windows and found only one solution, it was about the IIS.
The proccess: adding PHP_FCGI_MAX_REQUESTS=0 to environment variables.
The following setting works fine for Windows 2012 R2 Server !!!
http://i.stack.imgur.com/HrIaO.jpg
Control Panel-> System->Advanced System Settings->Advanced->Environment Variables->System Variables-> New -> Variable Name: PHP_FCGI_MAX_REQUESTS & Variable Value: 0

PHP, Memcached works from command line but not from the web

I have PHP 5.3.3 installed on Centos 6.4 with the memcached.so extension, and httpd is running with version 2.2.15-26. Here is my index.php:
$mc = new \Memcached();
$mc->addServer('127.0.0.1', 11211);
$mc->set("test", "blah");
var_dump($mc->getResultCode());
var_dump($mc->getResultMessage());
var_dump($mc->get("test"));
die;
When I run it from the command line, it works. I get the following:
10:22:33 $ php index.php
int(0)
string(7) "SUCCESS"
string(4) "blah"
The memcache server also works from telnet. However, when I run index.php from the web, it fails. I get the following (from viewing webpage source):
int(47)
string(51) "SERVER HAS FAILED AND IS DISABLED UNTIL TIMED RETRY"
bool(false)
Short of re-installing my OS and trying different versions of crap, can anyone explain what might cause this issue?
Is it an SELinux problem ? Cli can access to Memcached but daemon no. Try this :
getenforce to know if you have SELinux enabled
setenforce 0 to disable it
reboot
Retry your test
If is good, You must configure Apache to access to Memcached.
I have similar issue on CentOS and what I found it I am running SELinux which prevent httpd to connect to memcached. You need to set below,
# setsebool -P httpd_can_network_memcache 1
# getsebool httpd_can_network_memcache
httpd_can_network_memcache --> on
Please ensure that your memcache service should bind all IPs. Default value is 127.0.0.1. change it to 0.0.0.0 for supporting all defined Ips. In additional, don't forget to control your iptables or firewall.
I had this problem in WAMP 2.4, running a simple Memcache test script worked from the command line, but not in the browser.
The answer turned out to be stunningly mundane: WAMP had two php.ini files, and I was editing the wrong one.
E.g. Apache used this one: c:\wamp\bin\apache\Apache2.4.4\bin\php.ini
WAMP also had this one: c:\wamp\bin\php\php5.4.12\php.ini
Putting the extension=php_memcache.dll in the correct .ini file fixed things.
My clue something like this was the problem was that phpInfo()'s loaded config file reported different values in the two cases.
I had exactly the same issue as described by the OP. It turned out that the problem was caused by the server list the memcached extension maintains internally. My code was something like:
$serversList = $memcached->getServerList();
if (empty($serversList)) {
$memcached->addServer($host, $port);
}
My initial call to the testing script was done with a wrong value for $port. The call was done from web (apache) not from cli. After i corrected the port and i ran the code again, it was skipping the 'if' and used the existing servers list which was flawed and so it failed again.
Seeing the failure from the web i tested with the cli and it was working perfectly. In the cli the servers list was different from the one in the web. In fact, the server list was empty at each start of the script, even if my script was setting it with each run. Yet it was persisting between calls on the web.
Anyway, after clearing the servers list on the web and setting the correct server, it worked as expected from the web too.
When I look at examples I see it being used without the namespace "\" modifier. Try without it maybe?
http://www.php.net/manual/en/memcache.examples-overview.php
<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

Warning: exec(): Unable to fork in PHP

I'm using php 5 apache on windows server 2008, I have disabled IIS.
I m using exec command in my PHP script and it was working fine
but today I got an error:
Warning: exec(): Unable to fork
I gave permissions to cmd.exe in C:\Windows\System32 folder
but this did not fix the problem.
Specifically which permissions did you give to who?
Probably not to the right user..
Run this php script:
echo 'Script is executed by: ' . get_current_user() . getmygid();
It will tell you which user is running the PHP scripts and therefore which user to grant permissions to cmd.exe.
In 64-bit windows (e.g server 2008), theres a folder named c:\windows\syswow64, that contains all executables/dll, that are required by a 32 bit app. installed on your 64-bit machine.
Make sure your required 32-bit .exe/dll etc is placed in that folder.
if you cant find it there you will have to put a 32-bit version of the required .exe/dll
there.So this can used by yopur app/process.
Now when your 32-bit application/process executes, windows will automatically redirect your process to execute required app in syswow64 folder.
Hopefully that should resolve your compatibility issue.
I had this problem myself, but was eventually able to resolve it. The problem was due to how I had accidentally set cmd.exe to "Run as Administrator" by default. I say "accidentally" as I thought I was only setting the compatibility settings of a shortcut on my task bar, but it turned-out it was setting the compatibility of the .exe itself. Anyhow, I disabled this by deleting the registry key here:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
After doing this, everything started working again.

Categories