I have Apache server on my windows machine.
From PHP script I start .bat file using exec command(synchronously!).
From my batch script I run another executable(WinDBG). I run it asynchronously(using cmd start command) wait some time and kill if it is still running.
If I run .bat script from cmd it works as planned(asynchronously).
But if script is started from PHP exec command "start" works synchronously. And it is the same code.
I think that the problem is that PHP script run as a windows service. And therefore start work synchronously.
I should start WinDBG asynchronously to have ability terminate it
Related
I have a basic PHP script I am running through Windows Task Scheduler. The task runs well, but doesn't close the window once the script has completed. The script runs every minute, and we quickly get our server overran by the completed php.exe windows. Is there a way to close the CLI window if the script has completed?
I've searched around, but haven't found a clean answer. I'd prefer not to schedule another task to terminate php.exe if at all possible.
Thanks!
I am running a CLI windows php script which is mostly a LOOP with some CMD exec functions.
Problem is that these exec functions sometimes hangs up.
Can this script kill itself and restart itself ? '(for instance every 5 minutes)
Can this script kill itself and restart itself?
Not really, yet you can run another instance of itself and then quit the current one.
these exec functions sometimes hangs up
Then script cannot break from this by itself other by timeouting (see set_time_limit). Or you need to have separate watchdog to monitor your script and restarting it when needed.
(for instance every 5 minutes)
Rework your code to not loop and use cron or other scheduler (see What is the Windows version of cron?) to invoke your code periodically.
Okay, this is going to be a very weird request/question.
There is a very long running PHP script that needs to be launched by the user (admin) who is not very technically adept. When running the script through apache, it throws a timeout (502 or 504 Bad Gateway).
Let's just assume that apache can't be configured to fix the timeout issues.
I want to create a button in the admin panel that sends an AJAX call to a PHP script on the server, that PHP script will act as a proxy of sorts to launch a shell command. The shell command will then execute the long running PHP script with certain arguments... but I don't want it to wait for the long running script to finish. The proxy PHP script can exit and return true/false based on if the shell command actually started (this part is optional).
Essentially, have PHP launch a shell command which launches a PHP script.
How can I pull something like this off?
Have you tried shell_exec. It worked for me...
http://php.net/manual/en/function.shell-exec.php
Can we run PHP script just like jar's files.I want to execute PHP script in background without open it in browser.Is this thing possible ?
Using Crons we can run. Make a batch file with php commands and run it through task scheduler if you are using windows OS or run it as cron for apache.
I run PHP script in command line from CRON job. Once it complete a process, sometime PHP process still run on task manager as well as command prompt is active in windows forever, unless i kill manaully process from task manager. I put log file, it shows a code is working properly and end of the script. However, it does not exit from process and consume memory of server. I wonder is this bug of php ?
I run application in windows server 2003 and php is in CLI.