Kill background PHP script (shared hosting)

I created a script that runs in the background using the ignore_user_abort () function. However, I was stupid enough not to inject any code to stop the script, and now it sends emails every 30 seconds ...

Is there a way to stop the script? I host shared hosting, so I donโ€™t have access to the command line, and I donโ€™t know the PID.

+6
source share
4 answers

Is there a way to stop the script? I host shared hosting, so I donโ€™t have access to the command line, and I donโ€™t know the PID.

Then no.

But are you sure you donโ€™t have access to the shell? Even through PHP? If you do, you can try ...

<?php print `ps -ef | grep php`; 

... and if you can determine the process from this, then ....

 <?php $pid=12345; // for example. print `kill -9 $pid`; 

And even if you don't have access to shell command launches, you can find the pid in / proc (on a Linux system) and terminate it using the POSIX extension ....

 <?php $ps=glob('/proc/[0-9]*'); foreach ($ps as $p) { if (is_dir($p) && is_writeable($p)) { print "proc= " . basename($p); $cmd=file_get_contents($p . '/cmdline'); print " / " . file_get_contents($p . '/cmdline'); if (preg_match('/(php).*(myscript.php)/',$cmd)) { posix_kill(basename($p), SIGKILL); print " xxxxx...."; break; } print "\n"; } } 
+4
source

I came to this thread Yesterday! I mistakenly had an infinite loop on a page that should not have been visited, and that the increase in my I/O to 100 and CPU usage to 100 I/O was due to some php errors , and it was getting logged , and the log file size was less than thinks.

None of the above tricks worked on my shared hosting .

MY DECISION

  • In cPanel go to PHP version (except current)

  • Choose any version of PHP on time.

  • And then Apply Changes .

REASON WHY IT WORKS

the script, which had an infinite loop with some php errors, had a process, so I just needed to kill it by changing the php version, making it easier to restart services like php and Apache, and as the reboot was involved, previous processes were killed, and I was weakened while stabilizing the use of I/O and CPU . In addition, I fixed this error before manually changing the php version :)

+1
source

how did you deploy the script? you can simply delete it (if this is an acceptable option). otherwise, change it and insert some logic to allow it to send mail only once every n minutes / hours / days, depending on the time of the server?

repeatedly. stopping the execution of the script (or rather, the system trying to execute it), how did you plan to execute it? is it some kind of gui to crontab or something else? Can you not just undo what you did there (seeing that you do not have access to the command line / terminal)?

rob ganly

0
source

Simply. Call support, cancel it. Next time, do not do what you cannot control.

0
source

Source: https://habr.com/ru/post/896533/


All Articles