Note that there are some explanatory texts on larger screens.

plurals
  1. POGearman return value not working
    primarykey
    data
    text
    <p>I am trying to get gearman to return a value to php from a function after php makes a request to it using $gmclient->do("somefunction", "somedata"). However, the php client simply times out. The exact code I am using is straight from the php manual. I am using example #1 from <a href="http://docs.php.net/manual/en/gearmanclient.do.php" rel="nofollow">http://docs.php.net/manual/en/gearmanclient.do.php</a></p> <p>The browser gives me this message:</p> <blockquote> <p>This webpage is not available.</p> <p>The webpage at <a href="http://yoursite.com/client.php" rel="nofollow">http://yoursite.com/client.php</a> might be temporarily down or it may have moved permanently to a new web address.</p> <p>More information on this error. Below is the original error message</p> <p>Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error.</p> </blockquote> <p>The browser is Chrome if that helps to elaborate the error message.</p> <p>In case it makes a difference, the worker.php file is being executed in a terminal window using the command "php worker.php". I am running on Ubuntu 9.10 Karmic Koala. I installed gearman using the directions found at <a href="http://blog.stuartherbert.com/php/2010/02/26/getting-gearman-up-and-running-on-ubuntu-karmic/" rel="nofollow">http://blog.stuartherbert.com/php/2010/02/26/getting-gearman-up-and-running-on-ubuntu-karmic/</a></p> <p>I checked the terminal window and gearman is getting the request and echos the results into the terminal - it just not sent back to the client.</p> <p>The end goal is to get gearman to return to the client the return value from the function that was executed and display that value to the user.</p> <p>UPDATE:</p> <p>As requested, the code is below:</p> <p>worker.php (the worker)</p> <pre><code>&lt;?php echo "Starting\n"; # Create our worker object. $gmworker= new GearmanWorker(); # Add default server (localhost). $gmworker-&gt;addServer(); # Register function "reverse" with the server. Change the worker function to # "reverse_fn_fast" for a faster worker with no output. $gmworker-&gt;addFunction("reverse", "reverse_fn"); print "Waiting for job...\n"; while($gmworker-&gt;work()) { if ($gmworker-&gt;returnCode() != GEARMAN_SUCCESS) { echo "return_code: " . $gmworker-&gt;returnCode() . "\n"; break; } } function reverse_fn($job) { return strrev($job-&gt;workload()); } ?&gt; </code></pre> <p>client.php (client code - this is the page I am loading the browser)</p> <pre><code>&lt;?php # Client code echo "Starting\n"; # Create our client object. $gmclient= new GearmanClient(); # Add default server (localhost). $gmclient-&gt;addServer(); echo "Sending job\n"; $result = $gmclient-&gt;do("reverse", "Hello!"); echo "Success: $result\n"; ?&gt; </code></pre> <p>The comments below where it said it was working.. I repeat, it was NOT working. It only appeared to work because I changed $gmclient->do to $gmclient->doBackground which output the job ID, not the actual result from the function.</p> <p><strong>FINAL UPDATE (WITH SOLUTION)</strong></p> <p>After some work, I've figured out that it was not a coding error. Gearman was improperly installed. Instead of using apt-get install, I decided to do things manually. I downloaded the gearmand (c) from the gearman site (http://gearman.org/index.php?id=download). I then used the tutorials on the gearman site as well starting with <a href="http://gearman.org/index.php?id=getting_started" rel="nofollow">http://gearman.org/index.php?id=getting_started</a> and then <a href="http://gearman.org/index.php?id=gearman_php_extension" rel="nofollow">http://gearman.org/index.php?id=gearman_php_extension</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload