FATAL [ 0] gearman_packet_unpack_header:invalid command value - php

I'm trying to run the example Gearman worker from their documentation (see below), but every time I do I get a slew of errors in my Gearman log file like this: FATAL [ 0] gearman_packet_unpack_header:invalid command value. When I run the Gearman client (again, their own example), it doesn't seem to change anything. Nothing happens.
Here is the sample worker code that is failing
# Create our worker object.
$worker= new GearmanWorker();
# Add default server (localhost).
$worker->addServer();
# Register function "reverse" with the server.
$worker->addFunction("reverse", "reverse_fn");
while (1)
{
print "Waiting for job...\n";
$ret= $worker->work();
if ($worker->returnCode() != GEARMAN_SUCCESS)
break;
}
# A much simple reverse function
function reverse_fn($job)
{
$workload= $job->workload();
echo "Received job: " . $job->handle() . "\n";
echo "Workload: $workload\n";
$result= strrev($workload);
echo "Result: $result\n";
return $result;
}
>php -i:
extension version 1.0.2
libgearman version 0.29
Default TCP Host localhost
Default TCP Port 4730
>gearmand -V:
gearmand 0.29
How do I correctly configure Gearman to work? libgearman is the same version as gearmand, and my PECL extension is the most-recent stable version. I'm not sure what else to try.

As far as I was able to tell, the PECL extension for Gearman as version 1.0.2 does not work with Gearman version 0.29. I updated Gearman and libgearman both to version 0.33, and as soon as I did my extension was working.

Related

mamp pro, php 7.3.8 and remote mssql server

i use mamp pro on mac (catalina) and try to connect to remote mssql server.
in order to work with mssql i installed on the relevant php mamp folder:
brew install msodbcsql17 mssql-tools
pecl install sqlsrv pdo_sqlsrv
than i updated the php.ini file
extension=sqlsrv.so
extension=pdo_sqlsrv.so
when i try to run (of course with the correct credentails and server name)
$db = new PDO("sqlsrv:Server=MY.SERVER;Database=MYDBNAME", "MYUSER", "MYPASS");
i get this error:
Fatal error: Uncaught PDOException: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712
what am i missing?
The PHP-PDO driver wants to access MS-SQL-server via the ODBC driver of SQL-server.
You need to install the odbc driver by doing
brew install msodbcsql17 mssql-tools
Afterwards, you need to enable TCP connections on sql-server, add a login, add the login to the correct role, and then you need to open port 1433, so TCP connections to SQL-server can work (unless you have both PHP and the sql-server run on the same machine).
And you might have to install UnixODBC:
brew install unixodbc
Also, you might have to add php_odbc to extensions
extension=php_odbc.dll
and php-fpm uses another ini file than php-cli/php-cgi.
On ubuntu, the PHP-fpm ini file is in
/etc/php/7.2/fpm/php.ini
while the other is in
/etc/php/7.2/cli/php.ini
Another alternative, if you can't get ODBC to work, is to use PDO_DBLIB, which uses FreeTDS instead of ODBC. That might be better anyway.
sudo pecl install pdo_dblib
However, that restricts you to php > 5.03 < 6.0.0.
Maybe you can compile it from source.
Mine works on Linux, all I had to do was:
sudo apt-get install php-fpm php-dev php-pear
sudo pecl install sqlsrv pdo_sqlsrv
(msodbcsql17 and mssql-tools I already had installed)
add the lines
extension=sqlsrv.so
extension=pdo_sqlsrv.so
into both ini files, and done.
Then I executed the connection-test-sample
php ./test.php
(i have port 2017, on docker), and it worked:
<?php
$serverName = "localhost,2017";
$connectionOptions = array(
"database" => "MY_DB_NAME",
"uid" => "sa",
"pwd" => "TOP_SECRET"
);
// Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn === false) {
die(formatErrors(sqlsrv_errors()));
}
// Select Query
$tsql = "SELECT ##Version AS SQL_VERSION";
// Executes the query
$stmt = sqlsrv_query($conn, $tsql);
// Error handling
if ($stmt === false) {
die(formatErrors(sqlsrv_errors()));
}
?>
<h1> Results : </h1>
<?php
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
echo $row['SQL_VERSION'] . PHP_EOL;
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
function formatErrors($errors)
{
// Display errors
echo "Error information: <br/>";
foreach ($errors as $error) {
echo "SQLSTATE: ". $error['SQLSTATE'] . "<br/>";
echo "Code: ". $error['code'] . "<br/>";
echo "Message: ". $error['message'] . "<br/>";
}
}
?>
<h1>Results: </h1>
Microsoft SQL Server 2017 (RTM-CU16) (KB4508218) - 14.0.3223.3 (X64)
Jul 22 2019 17:43:08 Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 16.04.6 LTS)
I get a funny warning, though:
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib64/php/modules/pdo_sqlsrv.so' -
/usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol:
php_pdo_register_driver in Unknown on line 0
If I remove
extension=pdo_sqlsrv.so
then it works, without warning.
Note:
Just fixed the crap.
If you run php --ini, it will list you all the ini-files php loads.
The correct location (on Linux) to put these two lines is
/etc/php/7.2/mods-available/pdo.ini
The above warning occurs if extension=pdo_sqlsrv.so is loaded before extension=pdo.so. Also, that way, you only need to set the extension ONCE, and it's done for both php-cli and php-fpm. The mods-available are then (already) symlinked into php-fpm and php-cli.
You might have the same problem on Mac.
To make sure there are no permission issues, create a test user that is sysadmin:
-- The available default languages:
-- SELECT * FROM sys.syslanguages AS sysl
CREATE LOGIN [WebServicesTest] WITH PASSWORD = 'TOP_SECRET'
,CHECK_EXPIRATION = off
,CHECK_POLICY = off
,DEFAULT_LANGUAGE = us_english;
EXEC master..sp_addsrvrolemember [WebServicesTest], N'sysadmin';
To test if the connection is actually working with the user, you can use AzureDataStudio.
Beware:
If your system uses OpenSSL 1.1 (e.g. Ubuntu 19.04), you need to download the insiders-build.
TDS-based providers (freeTDS/ODBC) need TCP open, even if you work on localhost.
if anyone needs the answer
turned out need to install one more thing:
brew install msodbcsql#13.1.9.2 mssql-tools#14.0.6.0

Can't connect to memcached from PHP

CentOS version 6.8.
All things installed from yum.
php version 5.6.
memcached service installed and running.
also installed php-memcached module (not memcache).
When i try run this code from bash - it works well. When I try run it trough apache as a php page - it even not connect to the memcached server and not return any errors.
Code:
<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
$m->set('test_key','test_value');
print_r($m->get('test_key'));
?>
Memcached server is running in verbose mode (memcached -vv -m64 -l127.0.0.1). When I execute the code above from console, memcached server log is:
<28 new auto-negotiating client connection<br>
28: Client using the ascii protocol<br>
<28 set test_key 0 0 10<br><br>
>28 STORED<br>
<28 get test_key<br>
>28 sending key test_key<br>
>28 END<br>
<28 quit<br>
<28 connection closed.<br>
When I run it as trough apache - no any log messages in verbose console at all.

GearmanClient::do(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed in php shell_exec

I am trying to run gearman client from php shell_exec but it always throw following error GearmanClient::do(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:485 in /var/www/html/client.php
But if i run it from terminal then it works but not from php shell_exec. Even i passed server name and port in addServer method
I am running on centos 6.2.
Client.php
$client= new GearmanClient();
$client->addServer('127.0.0.1',4730);
print $client->do("reverse","Testing");
worker.php
$worker= new GearmanWorker();
$worker->addServer("127.0.0.1",4730);
$worker->addFunction("reverse", "my_reverse_function");
function my_reverse_function($job)
{
return strrev($job->workload());
}
Make sure your gearman packages are installed. Or manually installed if needed. Sometimes upgrading your system may cause your packages to be lost.
Second check your or launch it in debug mode as stated here http://gearman.org/getting-started/
gearmand -vvv
and then launch it run in the background
gearmand -d
I read on other questions treated to this matter that changes from
$woker->addServer('127.0.0.1',4730);
to
$worker->addServer('127.0.0.1:4730');
The same for $client->addServer('127.0.0.1',4730);

gearman gives me GEARMAN_COULD_NOT_CONNECT, it is definitely running

My dev server is Debian Squeeze and I'm running Gearman 1.1.5 which I compiled from source along with the php pecl extension v1.1.1
If I run the reverse_client.php script I get the GEARMAN_COULD_NOT_CONNECT error.
PHP Warning: GearmanClient::do(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:430 in /home/bealers/build/gearman-1.1.1/examples/reverse_client.php on line 26
There are a few similar posts on here about this and they all point to GM not running.
It is definitely running.
I'm starting it with these params:
PARAMS="--queue-type=MySQL --mysql-db=test_db --mysql-user=gearman --mysql-password=gearman"
If I drop the gearman_queue table in test_db then restart the daemon the table is recreated, so its mysql connection is fine and it's clearly starting.
I can also telnet to 4730 on localhost, so there's no firewall issue.
Initially GM had problems starting because it was starting before mysql, so I edited the init script
### BEGIN INIT INFO
# Provides: gearman-job-server
# Required-Start: $network $remote_fs $syslog mysql
and an update-rd.c gearman-job-server defaults sets it to start after and it starts fine on boot up now.
The only other thing I can think of is that initially I'd installed via apt but the version was to old so I removed it and compiled from source. /usr/sbin/gearmand no longer exists the only version is /usr/local/sbin/gearmand
ps ax | grep gearman shows only one process running.
Netstat shows only one process running`
tcp 0 0 *:4730 *:* LISTEN 2325/gearmand
The PECL lib seems fine:
php -i | grep gearman
/etc/php5/cli/conf.d/gearman.ini,
gearman
gearman support => enabled
libgearman version => 1.1.5
I'm out of ideas
I had the same problem and recently solved them after a couple days of frustration (hard to troubleshoot since there are three processes to worry about :-)
It appears (at least in my case) that the PHP documentation for GearmanClient::addServer() and GearmanWorker::addServer() is incorrect. Specifically, the docs seem to imply that hostname and port number are optional and that it will use localhost and port 4730 as defaults if you do not specify them. This never works - it suddenly occurred to me today to try explicitly specifying them for both client and worker processes and everything started working.
Try specifying all values for hostnames and ports and see if this works for you.
In case if you have used something like this
$client->addServers('127.0.0.1', 4730);
or
$client->addServers();
use something like this
$client->addServers('127.0.0.1:4730');
PS - I have used localhost IP, this can be replaced with actual host IP.
In my case it's little different. I got this same error when I had my addServer code inside the loop.
$client = new GearmanClient();
for ($i=0; $i<100000; $i++) {
$client->addServer("127.0.0.1", 4730);
$data = json_encode(array('job_id' => $i, 'task_name' => 'send-email'));
$client->addTaskBackground('sendEmail', $data);
}
$client->runTasks();
And this fixed it for me:
$client = new GearmanClient();
$client->addServer("127.0.0.1", 4730);
for ($i=0; $i<100000; $i++) {
$data = json_encode(array('job_id' => $i, 'task_name' => 'send-email'));
$client->addTaskBackground('sendEmail', $data);
}
$client->runTasks();
May be this could help someone.
If you want to use single server, you can use
$client->addServer($host, $port)
e.g. $client->addServer('127.0.0.1', 4730)
http://php.net/manual/en/gearmanclient.addserver.php
If you want to use multiple server, then you can use
$client->addServers($host1:$port1, $host2:$port2, $host3:$port3)
e.g. $client->addServers('127.0.0.1:4730', '127.0.0.2:8080')
http://php.net/manual/en/gearmanclient.addservers.php

Gearman , php extension problem : Class 'GearmanWorker' not found in .. using terminal but works on browser

I've installed gearman on ubuntu 10.04 recently and installed it's pecl extension. Now , when I run a php file in the browser that contains :
$client = new GearmanWorker();
die(var_Dump($client));
I get object(GearmanWorker)#1 (0) { }
but when running the a real worker file in terminal (by root) , I get this:
sudo php worker.php
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/imagick.ini on line 1 in Unknown on line 0
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
PHP Warning: Module 'pcntl' already loaded in Unknown on line 0
PHP Fatal error: Class 'GearmanWorker' not found in /home/ME/public_html/try/worker.php on line 3
The worker code :
#!/usr/bin/php
<?php $worker= new GearmanWorker();
$worker->addServer('127.0.0.1');
$worker->addFunction("reverse", "reverse_fn");
while (1) {
print "Waiting for job...\n";
$ret = $worker->work();
if ($worker->returnCode() != GEARMAN_SUCCESS)
break;
}
function reverse_fn ($job)
{
$workload = $job->workload();
echo "Received
job: " . $job->handle() . "\n";
echo "Workload: $workload\n";
$result = strrev($workload);
for ($i = 1; $i <= 10; $i ++) {
$job->status($i, 10);
sleep(1);
}
echo "Result: $result\n";
return $result;
}
Please help!
Type php --ini at your command prompt to see which php.ini your PHP CLI uses. Make sure Gearman is enabled in that php.ini.
using locate php.ini
in my ubuntu laptop show 2 results:
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini
add both extension=gearman.so into 2 php.ini file
then restart php and gearmand working now.
Install the gearman job server and libgearman
apt-get install gearman-job-server libgearman-dev
Install the pecl extension
apt-get install php-pear php5-dev
pecl install gearman
Open the correct php.ini file and add extension=gearman.so at the end.

Categories