I am trying to use XDebug with PHP and VS Code on Windows. I have successfully installed XDebug because it shows up in the phpinfo() page.
When I attempt to use XDebug on VS Code, I get this error:
DEBUG Checking PHPLS_ALLOW_XDEBUG
DEBUG The xdebug extension is loaded (2.7.1)
DEBUG Process restarting (PHPLS_ALLOW_XDEBUG=internal|2.7.1|0|*|*)
DEBUG Running C:\Users\***\Documents\Applications\php-7.3.4-nts-Win32-VC15-x64\php.exe -n -c C:\Users\***\AppData\Local\Temp\AF9E.tmp c:\Users\***\.vscode\extensions\felixfbecker.php-intellisense-2.3.10\vendor\felixfbecker\language-server\bin\php-language-server.php --tcp=127.0.0.1:50124 --memory-limit=4095M
DEBUG Checking PHPLS_ALLOW_XDEBUG
DEBUG Restarted (64 ms). The xdebug extension is not loaded
[Info - 11:04:12 AM] 1 files total
[Info - 11:04:12 AM] Indexing project for definitions and static references
Parsing file:///c:/xampp/htdocs/blank/blank.php
[Info - 11:04:12 AM] Indexing project for dynamic references
[Info - 11:04:12 AM] 0 Packages
[Info - 11:04:12 AM] All 1 PHP files parsed in 0 seconds. 148 MiB allocated.
I just had this issue too and looking at the configuration that was being provided (in the original example above it's C:\Users\***\AppData\Local\Temp\AF9E.tmp), I found that the zend_extension line had been commented out.
ie. it appears as this in the .tmp file:
;zend_extension=php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll
The semicolon being the commenting character.
A little experimentation showed that it was commenting it out itself based on the filename. I renamed the DLL to totallynotphpdebgr272.dll and set that as the zend_extension in php.ini. After that change it no longer commented that line in the generated .tmp file and I was able to start debugging php successfully in vscode.
Related
This is /etc/php/7.2/cli/conf.d/20-xdebug.ini content:
zend_extension=xdebug.so
xdebug.remote_enable=on
xdebug.remote_autostart=off
and this is the error I get by running php:
PHP Warning: Failed loading Zend extension 'xdebug.so' (tried: /usr/lib/php/20170718/xdebug.so (libc.musl-x86_64.so.1: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/xdebug.so.so (/usr/lib/php/20170718/xdebug.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
However /usr/lib/php/20170718/xdebug.so exists and has read permission:
# ls -l /usr/lib/php/20170718/xdebug.so
-rw-r--r--. 1 root root 2078128 Jan 16 11:15 /usr/lib/php/20170718/xdebug.so
Changing extension path to full path doesn't make a difference either.
What can be the reason?
It seems that shipped xdebug module was corrupted and installing it through apt solved the issue:
apt install php-xdebug
I also tried and compiled source code many times before installing it through apt but I got the same error every time I did. Yet the exact cause remains unknown.
Refer to the below link as I think it will solve your problem as it did for me
Installing Xdebug
Try this content inside your xdebug.ini file
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.show_error_trace = 1 <--- you can skip this
xdebug.remote_autostart = 0
I imagine you are using a mac, the C header files are no able to be reached via /usr/include. There are a few ways to fix this, but compiling it yourself is probably the best way. I would recommend https://bbqsoftwares.com/blog/xdebug-catalina if you don't want to turn SIP off.
=========================================================
Ignore this post. A much simpler statement of this issue can be found at PHP auto_prepend_file causes xdebug profiler to fail
=========================================================
Original Post (and updates)
When I try to open an xdebug profiler snapshot within PhpStorm using:
menu bar >> Tools >> Analyze xdebug profiler snapshot...
I select the file xDebug created but I'm faced with this error:
Error: Incorrect profiler snapshot format: Incorrect name format
I did not rename the snapshot. It is the default name: cachegrind.out.8008
php.ini
<!-- language:lang-none -->
[xdebug]
zend_extension="php_xdebug-2.5.5-5.6-vc11.dll"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir="C:\websites\xdebug"
; xdebug.profiler_output_name= ; Commented out to allow default name
xdebug.idekey=PHPSTORM
Why won't PhpStorm open the snapshot? Should I set a custom xdebug.profiler_output_name option?
Update
I closed all my projects, upgraded from PhpStorm 2017.1.4 to 2017.2, restarted Apache, deleted the old snapshots and created a new one. The new one opens without trouble.
Update 2
Seems that if I run a file from the command line by calling >php script.php, the generated snapshot can be opened. If I run the same file from the browser (meaning I go through the Apache webserver: localhost/script.php) the snapshot cannot be opened.
Update 3
I also notice that when I execute from the browser, I can't delete the snapshot until I force-stop the Apache process. The PHP file I'm profiling has no instructions: just <?php. Below are the two snapshots created:
When executed from the command line (PhpStorm opens this file without problem):
version: 1
creator: xdebug 2.5.5 (PHP 5.6.1-dev)
cmd: C:\path\to\script.php
part: 1
positions: line
events: Time
fl=(1) C:\path\to\script.php
fn=(1) {main}
summary: 0
1 0
When executed from the browser (PhpStorm cannot open this snapshot):
version: 1
creator: xdebug 2.5.5 (PHP 5.6.1-dev)
cmd: C:\path\to\script.php
part: 1
positions: line
events: Time
fl=(2) C:\path\to\script.php
fn=(1)
summary: 0
1 0
Update 4
The culprit is the auto_prepend_file ini setting. I had the following set in Apache Vhosts:
php_value auto_prepend_file "C:\path\to\init.php"
This file is run before Apache executes the script that was called from the browser. When I run the script from the command line, this setting (which is in my Apache Vhosts config) never takes effect so init.php doesn't run. Conversely, if I move the setting to php.ini where it also affects command-line execution, then snapshots generated from the command-line also stop working.
If I remove the auto_prepend_file setting, the generated profiler snapshot can be open without problem in PhpStorm. Of course this isn't a fix since I need the auto_prepend_file to execute for my application to work properly.
I've installed latest XAMPP server with PHP 7 (update: checked also PHP 7.1) (on my Windows 10 system). Wanted to use opcache, so I enabled it in php.ini.
[opcache]
zend_extension=php_opcache.dll
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
With that change now, and with almost every page refresh, I'm getting this error from Apache:
AH00428: Parent: child process 3748 exited with status 3221226356 -- Restarting.
So, page is loading, and loading... waiting to Apache start again. When I'm turning opcache off (by setting opcache.enable=0), Apache is not restarting and everything works fine (omitting the slower web application topic, of course).
Everything works fine while loading app on XAMPP having PHP 5.6 with enabled opcache.
EDIT (added GIF image):
As you can see, sometimes page refreshes like it should. But sometimes it's refreshing much longer, and Apache is restarting in that moment.
EDIT:
To be honest, I gave up with this application and working with PHP on Windows (was working on it for around 10 years with PHP <= 5.6). It's very hard/impossible (for now) to make PHP 7.x work on that OS (with Opcache). Decided to go with Ubuntu and server created with Docker. Everything is easier to configure (especially with Docker) and works faster. I advise everyone to do the same ;).
Your php_opcache.dll path seems wrong, you need write it like below, it works for me.
[opcache]
zend_extension=C:\xampp\php\ext\php_opcache.dll
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=256
opcache.max_accelerated_files=2000
More details
If your XAMPP comes with PHP 5.5+ by default, opcache already included in the bundle, you will just need to enable it. To enable the extension:
Open php.ini (by default it should be located here: C:\xampp\php\php.ini).
Add this line at the end of the file:
zend_extension=C:\xampp\php\ext\php_opcache.dll
Restart Apache server.
open a php.ini file
Change the ;opcache.enable=1 to opcache.enable=1
Add opcache dll path at the end of the file zend_extension = "C:\xampp\php\ext\php_opcache.dll"
Restart apache
for more reference check this video https://www.youtube.com/watch?v=GvWrNoRDjUY
In case of Xampp, just put the below lines next to [opcache]
zend_extension="C:\xampp\php\ext\php_opcache.dll"
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
To be honest - do not use xammp. Right now we have a bit better tech stack, to run PHP on Linux servers.
Docker
https://docs.docker.com/docker-for-windows/
Vagrant:
https://www.vagrantup.com/
Both of them are based on linux systems, where most of xammp problems will not have place.
First at all:
This is 2022 and I had a similar problem too with PHP-7.2, not on Xamp, but similar server.
How I've got my problem solved?
If you're here because of that, at first try to go with a default "opcache configuration options". And just above opcache.enable=1 put zend_extension=opcache. Your PHP is smart enough to find the extension. And yeah, there's no need to define the full path if you have defined it here extension_dir = [YOUR PATH] (in php.ini). Of course you can use the full path too, if you want too. The path, probably, it's not a problem if your extension is there (in the folder with all PHP extensions). Did you checked, is it there, your extension?
My problem was in this two options:
opcache.memory_consumption
opcache.interned_strings_buffer
I have no idea why, but I guess this two option should have some balance, because both of them is about memory usage.
So, this had my Apache useless, because it didn't wanted to start
opcache.memory_consumption = 64
opcache.interned_strings_buffer = 32 ;this one BAD
next one works fine!
opcache.memory_consumption = 64
opcache.interned_strings_buffer = 16
this one is works fine too!
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 32
So, as I said, at first try to go with a default values of "opcache configuration options", and later do experiments.
How to check everything works on PHP?
var_dump ( zend_version() );
var_dump ( extension_loaded("opcache") ); // bool(false) cuz it's ZEND
var_dump ( extension_loaded("Zend OPcache") ); // bool(true)
// Next one will give you a lot of data about current opcache usage,
// but of course, only if your extension is enabled.
print_r ( opcache_get_status() );
Default OPcache configuration options you can find here:
https://www.php.net/manual/en/opcache.configuration.php
Creeating directory with appropriate permissions and setting it php.ini worked!
opcache.file_cache=d:\xampp\htdocs\opcache
ThreadStackSize 8388608
Helped me in the similar case. This is a httpd option.
on php.ini add more
zend_extension=opcache
remove comment
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=256
opcache.max_accelerated_files=10000
restart apache
On Mac OSX Mavericks using homebrew php55 whenever I run a a php command I get the following error message (everything runs fine it's just annoying)
PHP Warning: Module 'intl' already loaded in Unknown on line 0
I ran
php --ini
and the output was
php --ini
PHP Warning: Module 'intl' already loaded in Unknown on line 0
Warning: Module 'intl' already loaded in Unknown on line 0
Configuration File (php.ini) Path: /usr/local/etc/php/5.5
Loaded Configuration File: /usr/local/etc/php/5.5/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.5/conf.d
Additional .ini files parsed: /usr/local/etc/php/5.5/conf.d/ext-apcu.ini,
/usr/local/etc/php/5.5/conf.d/ext-igbinary.ini,
/usr/local/etc/php/5.5/conf.d/ext-intl.ini,
/usr/local/etc/php/5.5/conf.d/ext-memcached.ini,
/usr/local/etc/php/5.5/conf.d/ext-mongo.ini,
/usr/local/etc/php/5.5/conf.d/ext-uuid.ini,
/usr/local/etc/php/5.5/conf.d/ext-xdebug.ini
Checked in the php.ini file and the only place intl is loaded is at the top and it's commented out. The other files contents look something like:
extension="/usr/local/Cellar/php55/5.5.23/lib/php/extensions/no-debug-non-zts-20121212/intl.so"
where the contents after the last slash is the extension.
I'm not sure where else to look.
Any help is appreciated
I think you have loaded Xdebug probably twice in php.ini.
check the php.ini, that not have set xdebug.so for the values extension= and zend_extension=.
Check also /etc/php5/apache2 and /etc/php5/cli/. You should not load in each php.ini in these directories the extension xdebug.so. Only one file, php.ini should load it.
Note: Inside the path is the string /etc/php5. The 5 is the version of PHP. So if you use another version, you always get a different path, like php7.
I had the same issue on mac i.e. Warning: Module 'pdo_pgsql' already loaded in Unknown on line 0.
Here's how I solved it.
Locate the folder conf.d, mine was in the directory
/usr/local/etc/php/7.0/conf.d.
In this folder, there's a file called ext-pdo_pgsql.ini.
Type sudo nano ext-pdo_pgsql.ini to edit it.
There should be a line extension="/usr/local/opt/php70-pdo-pgsql/pdo_pgsql.so". Comment it
out by adding semi-colon to the beginning of the line i.e.
;extension="/usr/local/opt/php70-pdo-pgsql/pdo_pgsql.so".
Save the file. (I usually run control + O, control + M).
Exit the file (control + X).
Hope this helps someone.
To fix this problem, you must edit your php.ini (or extensions.ini) file and comment-out the extensions that are already compiled-in. For example, after editing, your ini file may look like the lines below:
;extension=pcre.so
;extension=spl.so
Source: http://www.somacon.com/p520.php
You should have a /etc/php2/conf.d directory (At least on Ubuntu I do) containing a bunch of .ini files which all get loaded when php runs. These files can contain duplicate settings that conflict with settings in php.ini. In my PHP installation I notice a file conf.d/20-intl.ini with an extension=intl.so setting. I bet that's your conflict.
In my case I had uncoment the ;extension=php_curl.so in php.ini, but Ubuntu was already calling this extension somewhere else.
To find this "somewhere else", on php.ini will informe. On my case:
/etc/php/7.1/apache2/conf.d/20-curl.ini was the path.
So now we edit this file (terminal):
sudo nano /etc/php/7.1/apache2/conf.d/20-curl.ini
Comment the ;extension=php_curl.so
Save file and restart apache:
sudo systemctl restart apache2
solved by commenting extension=curl
For issue related to code igniter project upload,
go to the base directory index.php and add this code:
if ($_SERVER['SERVER_NAME'] == 'local_server_name') {
define('ENVIRONMENT', 'development');
} else {
define('ENVIRONMENT', 'production');
}
if (defined('ENVIRONMENT')){
switch (ENVIRONMENT){
case 'development':
error_reporting(E_ALL);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
For shared hosting, in cPanel I unchecked the Module in question under "Select PHP Version" > "Extensions" and the error disappeared for PHP 7.4.
I had the same issue after upgrading from Fedora Server 24 (PHP 5) to 25 (PHP 7). After investigation, I found that /etc/php.d/ had two different .ini files loading extension=geoip.so.
Previous version of distros had this file named 50-geoip.ini but the recent was changed to 40-geoip.ini, and I suspect that in the version-upgrade process the old hasn't been removed, while the new one has been created.
That was the actual case of the issue. After removing stray 50-geoip.ini from /etc/php.d/ and restarting httpd it just worked flawlessly.
I deleted the 20-mongo.ini file in /etc/php5/cli/conf.d and this solved the problem.
I figured this out by printing the PHP configuration and searching by xml.ini. Notice in the following output how xml is loaded twice (first as 20-xml.ini and then as xml.ini):
$ php -i | grep xml
/etc/php.d/20-simplexml.ini,
/etc/php.d/20-xml.ini,
/etc/php.d/20-xmlwriter.ini,
/etc/php.d/30-xmlreader.ini,
/etc/php.d/xml.ini
xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
libxml Version => 2.9.1
libxml
mbstring.http_output_conv_mimetypes => ^(text/|application/xhtml\+xml) => ^(text /|application/xhtml\+xml)
xml
libxml2 Version => 2.9.1
xmlreader
xmlwriter
libxslt compiled against libxml Version => 2.9.1
There are two "php_intl.dll" files inside php.ini file on 872 and 968 number lines. if php warning module 'intl' already loaded in unknown on line 0 this message is focused on your CLI. Then you should have to remove the semiclone prefixes on line 872. I expect this will done.....
Just for the record as it might help others who are on shared hosting (cPanel).
I had error on shared hosting php7.2:
Module 'imagick' already loaded in Unknown on line 0
In the beginning hosting provider said it was my bad configuration (running Yii2.16). But after I showed them, that all Internet related this issue to server configuration -they started to listen to me. After I proved, that there was no error on php7.1 they started to search for the error.
As they told to me - the error was due to configuration in PERL modules or PEAR package, but they did not told me the real issue.
So, if you are on shared hosting - talk to you provider and experiment with PHP versions (if you can change them).
Comment out these two lines in php.ini
;extension=imagick.so
;extension="ixed.5.6.lin"
it should fix the issue.
In Windows 10, I fix this by comment like this
;extension=php_sockets.dll
Run php --ini and notice file path on Loaded Configuration File.
Then run command like cat -n /etc/php/7.2/cli/php.ini | grep intl to find if the extension is commented or not.
Then update loaded configuration file by commenting line by adding ; such as ;extension=intl
This can happen when you install php-intl package and also enable the same extension on php.ini file.
If you are on shared hosting, just apply the default php settings. Cpanel overrides php settings to default.
I am using WAMP in Windows 10 with PHP 7.2.10. I was able to solve it through commenting the line extension=ftp in php.ini inside wamp64\bin\php\php7.2.10 .
I am unsure but my guess why this happens is that my php.ini inside wamp64\bin\apache\apache2.4.35\bin already loads this module.
Be sure to restart all services of WAMP after doing so.
I had the same issue so I commented the extension=mysqli as I included this to run sql server. Check if you have uncommented this extension=mysqli if so, place ; in php.ini
I resolved this issue by removing php.ini file from extension=grpc commenting like this ;extension=grpc
I had a similar problem, the problem was that the extension intl was duplicated.
You can check in file C:/xampp/php/php.ini and find "intl". In my case extension=intl is already present and I scrolled again and found a second intl "extension=php_intl.dll".
The extension must one to execution can't execution extension intl again. This will show error like this "Module 'intl' already loaded".
I fixed it by commenting out extension=php_intl.dll using ";" like this ;extension=php_intl.dll. and restarted the apache service.
I am getting both modules listed as installed / configured when I use:
php -m
or if I use:
php -i
but when I use:
$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or
$m = new Memcached;
I get the following error:
Fatal error: Class 'Memcached' not found
I am running on a Mac - OS X (10.5.7) with default install of apache & php. Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. I have restarted apache tons of times and even done a machine restart.
Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? I am literally stumped, after 3 hours of googling, I am just about ready to give up.
Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini
UPDATE:
Apache is failing to load the extension.
[Fri May 14 04:22:26 2010] [warn]
Init: Session Cache is not configured
[hint: SSLSessionCache] PHP Warning:
PHP Startup: Unable to load dynamic
library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so'
- (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load
dynamic library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so'
- (null) in Unknown on line 0
Does anyone know why or how this would happen? Both of the files referenced above DEFINITELY ARE there. Should I move this question to server fault?
Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors.
It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). Or it may be a permissions problem on the shared object file. Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots).
HTH
C.
because both versions use different php.ini
place your php.ini into location noted in the phpinfo() outout
I would suspect that the issue revolves around permissions. When you run php from comand line, it runs as the user invoking it. When run as an apache module, it runs as "nobody".
I would assume that the memcached.so file, or the directory it's in does not have proper permissions.
I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo(). Mine was a permissions problem because of selinux on a CentOS machine. I had to change ownership and permissions and now it is working as expected.
Set php path in environment variables as given below.
Right-click on "My Computer"
Properties
Advanced Tab > Environment Variables
Under System variables, scroll down to find "Path", select and click on Edit.
Add path to your php install on the end (make sure to precede with semi-colon ";"). Example: ";C:\php7"
Click Ok.