0
Hello,
I’m having a problem related to a PHP system running through a Windows Service.
The application works as follows:
- 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.
- 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)
- 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)
ordie()
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()
ofSystem.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?
– Gonçalo
The process that gets tightened is from iexplore or cmd? vc calls php so:
php -f arquivo.php
?– rray
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?– Daniel Omine
@Gonçalo I never used this tag, could send me an example?
– KhaosDoctor
@rray No, I’m using the command normally
php arquvo.php params
– KhaosDoctor
@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...
– KhaosDoctor
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
– Daniel Omine
@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– KhaosDoctor
I think part of the problem may be how the C# program creates the process.
– Daniel Omine
@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.
– KhaosDoctor