Php-language-server: Cpu load, memory leak

Created on 22 Aug 2017  路  22Comments  路  Source: felixfbecker/php-language-server

mac sierra
Code 1.15.1
Php instellisense 1.15.0
php 7.1.6_18

Cpu load 95% with no tabs opened, memory usage gradually increased by 1-2 mb in 10 secs
Maybe this will help:

[php_intellisense_1.5.0.txt](https://github.com/felixfbecker/php-language-server/files/1240892/php_intellisense_1.5.0.txt)

help wanted needs more info

Most helpful comment

I have the same problem, PHP Language Server consume 100% cpu and Load average is +10.
How can I debug was is going on?
The worst is that when I close Atom, PHP Language Server is still running..

All 22 comments

I also see a PHP process start and utilize a full core of my CPU as soon as I open VSCode.

OSX 10.12.5
VSCode 1.15.1
PHP Intellisense 1.5.1

EDIT: Err, it seems to be gone now. I saw it running for a while last night, maybe it just took a while to scan my current project? It is rather large.

"All 8812 PHP files parsed in 492 seconds. 160 MiB allocated"

What is the bug here? The language server needs to build it's index the first time when it's not cached, it's expected that this takes some CPU and RAM

It looks like there's no caching, and every time you open a project with VS CODE, a parsing process is opened.

dependencies are cached

+1 i have the same problem. Everytime i relaunch Vscode, parsing starts from begining and dependencies are not cached - it may be because i have 2 separate folders and each of them has one composer.lock file.
Also i have large php projects where i don't use composer so all files are parsed on start. It would be nice to manually specify which files should be cached.

Ubuntu 17.10
VS Code 1.19.1
PHP Intellisense 2.2.2
Memory Size: 16G, almost used by a process called "PHP Language Server"

$ ps -ef | grep -E "9099|6596"
catroll   6596  6541  1 09:50 ?        00:00:07 /usr/share/code/code --nolazy --inspect=9333 /usr/share/code/resources/app/out/bootstrap --type=extensionHost
catroll   6629  6596  1 09:50 ?        00:00:04 /usr/share/code/code /usr/share/code/resources/app/extensions/html/node_modules/vscode-languageclient/lib/utils/electronForkStart /usr/share/code/resources/app/extensions/html/server/out/htmlServerMain.js --node-ipc --clientProcessId=6596
catroll   9302  6596 99 09:56 ?        00:00:19 PHP Language Server
catroll   9364  5172  0 09:57 pts/0    00:00:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn -E 9099|6596

I'm seeing this too, even when launching simple projects.

Could you try setting COMPOSER_ALLOW_XDEBUG=1 with XDebug on, then see if the language server crashes with a max recursion limit reached error?

I have found a bug with the recent foreach handling, this is a case that causes an infinite loop:

$a = [];
foreach ($a as $k => $a) {
}

I have a fix but it's not very nice yet, working on it.

@jens1o you say the project you're seeing this on is simple, can you confirm if you have something like the above?

Another example is

foreach ($a->getArray() as $k => $a) {
}

Edit: to be clear, the issue I'm seeing occurs when you overwrite the variable being iterated with the foreach value, in the cases above, $a

Yes, it has. It really looks like an infinite loop.

I have the same problem, PHP Language Server consume 100% cpu and Load average is +10.
How can I debug was is going on?
The worst is that when I close Atom, PHP Language Server is still running..

I also have a continuous high cpu on windows running with vscode. After vscode closes the process remains with high cpu and I have to kill it manually.

image

edit: cpu load and memory usage are stable remaining at ~34% and ~115Mb

Is this still happening?

It is still happening. I came from https://github.com/atom/ide-php/issues/108 and I had to disable the atom extension because of the high CPU usage.

screen shot 2019-01-21 at 13 05 49

php-ide version: 0.7.18
OS: macOS Mojave

Hi, I have the same issue with Windows 8.1, Atom 1.34, ide-php 0.7.18
PHP CLI remains even though I'm not doing anything in Atom and initialization is done
2019-01-25_1741
Also the initialization occurs each time I start Atom (about 25s)

Also having this problem on Ubuntu 18.04 + Atom and VS Code

This is still happening with IDE-PHP atom extension.

A simple php file with php_info(); eats up a whole CPU indefinitely.
php-language-server-cpu-load

This may be related in some way to a bug I was having in my own extension. In my extension, I notice that php child processes were failing to be killed and continue to absorb memory and cpu power. I hacked around this on linux platforms by being really aggressive about killing child processes like this:

function phpCliKill(command: ChildProcess) {
    if (!/^win/.test(process.platform)) {
        exec(`ps -ef | awk '/phpcs/ {print $2" "$8" "$4" "$7}'`,
            (err, stdout) => {
                if (err) {
                    window.showErrorMessage('Sniffer: Error trying to kill PHP CLI, you may need to kill the process yourself.');
                }
                stdout.split("\n").forEach(($process) => {
                    const killable = $process.split(" ");
                    if (killable[1] === "php" && parseInt(killable[2]) > 90) {
                        exec(`kill ${killable[0]}`);
                    }
                });
            });
    }

    command.kill();
}

and then calling it on a timeout.
setTimeout(() => !sniffer.killed && phpCliKill(sniffer), 3000);

I have not taken the time to develop a similar method for windows or see if this works on osx but I think.

Anyway I don't know if thats helpful, but it could be a similar problem.

Still having issues on high memory consumption of the extension.
Here is what process explorer looks even if I just open a workspace with one folder full of pure php files.
vscode_process_explorer

Still having this issue:

OS: Mac OS 10.15
Extension version: 2.3.14

same issue for me
Ubuntu Verison : 20.04
Vscode version: 1.51.1
Tried with the latest vscode extension

when installing PHP intelliSense or PHP intelephense the PHP language server starts using almost 100 percent CPU. So issue is not only with PHP intelliSense but also with PHP intelephense

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jarzebowsky picture Jarzebowsky  路  8Comments

felixfbecker picture felixfbecker  路  4Comments

felixfbecker picture felixfbecker  路  9Comments

Ciantic picture Ciantic  路  7Comments

Morgy93 picture Morgy93  路  5Comments