This hasn't a thing to do with PHP. PHP's responsibility ends with the sending of the result to the client, and all communication is terminated. You must use AJAX to send requests in the background, in which case the PHP processes the request again as per a normal brand new request. So it doesn't matter if its done with AJAX or not, you simply handle the querystring request / post request as per a normal HTML request on the PHP end. If AJAX is in use, it handles both the sending and receiving of the request and parsing it for relevant data.
You'll want to make sure you put a delay on there as well. If you run it in real time on each keystroke, you can potentially run hundreds of queries per minute against the database.
header('HTTP/1.1 420 Enhance Your Calm');