You're supposed to run the worker script from the console (or under something like GearmanManager or supervisord (or screen)), where it'll connect to gearmand, register it function and wait for work to be handed over to it from gearmand.
The flow of execution would be something like this:
Start a worker in a console terminal
GearmanWorker -> register function -> gearmand
A web request arrives
browser -> request page -> GearmanClient
GearmanClient -> perform this function -> gearmand
gearmand -> here, do this function -> GearmanWorker
GearmanWorker -> here's the result -> gearmand
gearmand -> we're done, this is the result -> GearmanClient
GearmanClient -> return data to executing php -> browser
Hopefully that explains a bit more how things are interconnected, and why you didn't get a result the first time if you didn't have the worker actually running somewhere and registered with gearmand when the client were executed.