your server routine is just a web page,wait for the browser to request.you set up the autocomplete like this: $(..).autocomplete(web_page_url,{options..}).every time when the user press a key,autocomplete will make a request to your web page,you fetch the parameter q,and you will know what the user have put in the autocomplete textfield.then you run your routine,and at last,write the response like this: fog fox one item a line,so autocomplete will know.
the autocomplete plugin bundle file comes with some .php files,that is server-side code,you can review it.