11

I have a php script that I have been developing which calls an external api within a loop. It is being tested on a VPS which is running LAMP on Debian. I noticed this morning that the api was not responding to my script. When I called the provider, they told me that my server had been calling the api 1000's of times per hour for the past 10 hours. I am assuming that a php script (which I have been working on the day before and testing on my VPS) entered into an infinite loop during one of the executions, and never came out (I have been testing it from the command prompt, and not over the web.) I have attempted to stop and start Apache, but the api support staff says that the calls are still coming in from my server address. How can I find and stop the process? Also, is there a possibility that the Apache stop/start solved the problem, but the api is still trying to sort through past calls?

Please forgive me for not using my local test environment correctly.

Edit: I do not know the process name, I need to discover the name (or pid) based on behavior.

Hoytman
  • 355

2 Answers2

22

Since you were manually running the php binary, either by using php or by using the php shebang at the top of the script, you'll need to find it's PID and kill it.

You can use pkill -9 php or if pkill itsn't present you can use ps -efw | grep php | grep -v grep | awk '{print $2}' | xargs kill to kill all php processes.

In addition if a process is making outgoing network connections to an external API, those connections will show up in a netstat.

You should be able to do a netstat -anop to show you all connections and the PID of the process that controls them. Find out IP/hostname of external API server, find that IP/hostname in the netstat list, kill related PID.

ThatOneDude
  • 2,774
  • 17
  • 18
4

If i understood correctly your Post, you ran a Script from PHP-CGI through your console that it probably something gone wrong and spammed API's Servers.

So There are many possibilities that may caused this problem. First of all, when you are executing a PHP Script just buy typing "php scriptname.php" it waits for PHP Script to end and then is returning to your main Session Input. If you close your shell during the execution of the script it will stop its operation. Unless you started your PHP with a "screen" or "&" there is not a single possibility the script to continue running.

Now lets analyze its operation. If the script gone into an infinite loop , opening a socket, that means that it would try to connect to the API's Server Like hundred times per second. That means that the target server should ban you from the first 10 seconds. Something you haven't clarified to us is, the flowrate of the connection requests to target server. Does the API's Support provided you any more information about that? And if yes what did they said.

Having said that your VPS still sending requests to the Servers i would suggest you to do

ps -A xa | grep php

and check for running php instances. You might accidentaly started a php script in background by adding a & to the end of the line. If this command return something. Find application's pid, and terminate it with the following command

kill -9 pid

If that doesn work , restart your vps and ask them if it still send them connection requests (something that is currently impossible, and that would mean that their firewall placed your packets in slow mode (meaning that it queued them with a delay to their servers))

Devian
  • 596