Is it possible to check what a PHP script does when it is already running?

I have a PHP script that runs for a week, since it does a lot of number crunches - it didn't hang, just doing a lot of work. The problem is that I don’t know what this led to, and therefore I don’t know if it will end in 1 hour or 1 month. (Yes, I had to put something there for him to tell me, but it's too late for that now.)

Is there any way to find out what the script is doing? Or is it even better to extract variables from the current state?

+4
source share
4 answers

On Windows, you can check what php.exe does with Microsoft procmon.exe . It will not give you full feedback on variables, etc., but you can check any operations with the file system (which php does very often). PHP has some internal functions stored as additional .exe. You can check with procmon if PHP calls them ...

0
source

I hope the script has completed its tasks by now. As a general guide to Linux, you check what happens to processes running on your system with the top command. This gives you a window of all running processes.
To concentrate on one process, you can get its PID (Process ID) with the ps command. So you can run:

$ ps -e

This command will produce 4 columns. The left column is the PID, and the right is the name of the script. Let's say you find the script name in the right column, and you check that its PID is 3468. Then do

$ top -p 3468

you get a periodically updated top window. You can select various information. Usually you check% CPU and VIRT first. The VIRT column is useful because if it is constantly increasing, it is an almost certain sign of a memory leak in the script.
Alternatively, you can use htop and highlight the process that you selected, if installed on your system.

0
source

I wrote some PHP scripts that take a lot of time. Usually I have a script to update the database table with some statistics occasionally (for example: if every 10,000 cycles in the cycle, depending on the weight of the cycle ... also take samples of microgrids to see how long a certain step takes), then I can check the table for "statistics" to see how the script is executed, or which step it is located.

I would agree that others said that PHP is not the best language for this, but as a last resort I found that this method works well (I have had PHP scripts stable for several months).

0
source

Already suggested answers .. Just show that the script is working. This, as you said, is not your need ...

As for a script already running that does not register / does not store any information. Well, the only true option I can come up with is to check what it handles. So if this is file / database processing .. you should be able to see modified / changed results.

If its all pure in memory, yours is more or less out of luck if you are not using something like a session.

But just checking if the script works ... is not needed at all ..., so if its processing a database, checking the database, if its processing files, check the files. Otherwise, your way out of luck.

When it comes to heavy cruncher scripts like when I do geocoding ... I store the results / processed data in local files. Therefore, if the script fails or stops. I can resume .. But in favor of this, I can run another script and read these files and see the progress or the last step.

Can it resume or start again? If it can be resumed, stop it and write it down or something so that you can control it? Otherwise, you just need to wait until it finishes.

0
source

All Articles