PHP processes never close

Asked

Viewed 246 times

0

Hello,

I’m having a problem related to a PHP system running through a Windows Service.

The application works as follows:

  1. I have a folder with several files and PHP scripts that serve as an offline application, which always runs on the localhost, connects to the database, performs some specific functions and then finishes its work.
  2. There is a windows service (done in C#) that is in charge of running this task every X minutes (a time parameterizable through a configuration file)
  3. Given its time, the service executes the PHP script that is in its settings and it performs the functions with perfection.

So far it’s all right, my script works, but I’ve noticed that even after the script’s completion, the process PHP.exe*32 and conhost from the windows command window still running in the task manager. And over time these processes pile up to 800 or more processes php.exe who are doing absolutely nothing but consume memory.

Here’s what I’ve tried

  • I’ve tried to put exit(0) or die() at the end of the scripts to see if it killed the process
  • I tried to change my windows service by contemplating the Process.Kill() of System.Diagnostics
  • I tried to change the PHP execution parameters on the setando server max-execution-time for 60s

None of the options had any effect, however I realize that this occurs in certain processes, I have 3 services of these, each one running a different file and apparently only 1 of them presents this problem.

I wonder what would be the logic that PHP performs to kill these processes or how I can force the script to kill its own process at the end of the execution so that there are no such stacks of processes running.

I am using Codeigniter in PHP scripts.

  • Have you tried using the break tag; to try to stop processes?

  • The process that gets tightened is from iexplore or cmd? vc calls php so: php -f arquivo.php ?

  • The command taskkill /PID numero does not solve? Or you want a way to understand the reason for continuous execution to prevent it from occurring in the future?

  • @Gonçalo I never used this tag, could send me an example?

  • @rray No, I’m using the command normally php arquvo.php params

  • @Danielomine The problem, Daniel, is that this application is more or less Autonoma, I install it in an endpoint and it’s there running alone, I can’t run the taskkill in the PID, because that would be another logic to just close open processes...

  • 2

    I suspected that was the case. One way to avoid this disorder is to have control over the processes. In php.net there are examples in php-Posix pages. Although Posix is linux only, there are examples of users under pid control under Windows environment. Of course they are generic examples, some with bugs, outdated, etc. But it is already a way to understand what to do. You will also find the getmypid() function. It may be useful if you can control the process. Only be aware of the notice in the http://php.net/getmypiddocumentation

  • @Danielomine I managed to perform the Kill of the PHP process through of this link, but I noticed that even killing the PHP process, the process cmd stays open

  • I think part of the problem may be how the C# program creates the process.

  • @Danielomine The problem is that after running the CMD process on C# I figured it was keeping open, so I added a process.Kill() and it’s not closing anyway.

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.