what is the correct syntax of BLPOP on Predis? - php

I do it like this:
$r = new Predis\Client($single_server, $options);
$retval = $r->blpop('queue:query');
But I get this error:
ERR wrong number of arguments for 'blpop' command
Whenever I do this
$r = new Predis\Client($single_server, $options);
$retval = $r->blpop('queue:query',0);
I get the error:
Error while reading line from the server
Doing it from redis-cli
redis 127.0.0.1:6379> BLPOP queue:query
(error) ERR wrong number of arguments for 'blpop' command
redis 127.0.0.1:6379> BLPOP queue:query 0
1) "queue:query"
2) "hello world"

Seems like a bug. The latest version doesn't have this issue, also it apparently dropped namespaces:
<?
include_once "Predis.php";
$r = new Predis_Client();
$retval = $r->blpop('queue:query',0);
var_dump($retval);
?>
It blocked when I accessed the page. Then, I issued LPUSH queue:query 0, went back to the page, and got this:
array(2) { [0]=> string(11) "queue:query" [1]=> string(1) "0" }
Nevertheless, I would recommend the use of phpredis, it is faster than this library, because it is compiled as a php extension. If you have the rights in your server, that's a good pick.

Related

mongoDB php doesn't find database but is successfully connected to the server

when I connect to my mongoDB database with PHP, the variable sometimes contains an empty array but when pinging it, the array contains data. The empty arraay appears when I just restarted the apache2 webserver. I guess there are some other ways to cause it but I can't find a way on how to do that.
This is not my only issue. When I select a database, the variable contains NULL so I can't select a collection. It's also very hard to find an up to date documantation because these two are outdated.
Now to all my code:
$mongo = new MongoDB\Driver\Manager("mongodb://root:pwd#localhost:27017");
var_dump($mongo);
sometimes returns:
object(MongoDB\Driver\Manager)#1 (2) { ["uri"]=> string(47) "mongodb://root:pwd#localhost:27017" ["cluster"]=> array(0) { } }
Sending a ping to the database before printing the database:
$mongo = new MongoDB\Driver\Manager("mongodb://root:pwd#localhost:27017");
$command = new MongoDB\Driver\Command(['ping' => 1]);
$mongo->executeCommand('db', $command);
var_dump($mongo);
returns:
object(MongoDB\Driver\Manager)#1 (2) { ["uri"]=> string(47) "mongodb://root:pwd#localhost:27017" ["cluster"]=> array(1) { [0]=> array(10) { ["host"]=> string(9) "localhost" ["port"]=> int(27017) ["type"]=> int(1) ["is_primary"]=> bool(false) ["is_secondary"]=> bool(false) ["is_arbiter"]=> bool(false) ["is_hidden"]=> bool(false) ["is_passive"]=> bool(false) ["last_is_master"]=> array(10) { ["ismaster"]=> bool(true) ["maxBsonObjectSize"]=> int(16777216) ["maxMessageSizeBytes"]=> int(48000000) ["maxWriteBatchSize"]=> int(100000) ["localTime"]=> object(MongoDB\BSON\UTCDateTime)#2 (1) { ["milliseconds"]=> string(13) "1618843900377" } ["logicalSessionTimeoutMinutes"]=> int(30) ["minWireVersion"]=> int(0) ["maxWireVersion"]=> int(6) ["readOnly"]=> bool(false) ["ok"]=> float(1) } ["round_trip_time"]=> int(0) } } }
Now my not found database:
$mongo = new MongoDB\Driver\Manager("mongodb://root:pwd#localhost:27017");
//Ping the database
$command = new MongoDB\Driver\Command(['ping' => 1]);
$mongo->executeCommand('db', $command);
//select the hltv database
$db = $mongo->hltv;
var_dump($db);
returns:
NULL
The error log shows:
PHP Warning: Undefined property: MongoDB\\Driver\\Manager::$hltv in /var/www/hltv/index.php on line 6
When trying to list all Databases:
$mongo = new MongoDB\Driver\Manager("mongodb://root:pwd#localhost:27017");
//Ping the database
$command = new MongoDB\Driver\Command(['ping' => 1]);
$mongo->executeCommand('db', $command);
//list databases
var_dump($mongo->listDatabases());
returns a blank screen and shows following error:
PHP Fatal error: Uncaught Error: Call to undefined method MongoDB\\Driver\\Manager::listDatabases() in /var/www/hltv/index.php:6\nStack trace:\n#0 {main}\n thrown in /var/www/hltv/index.php on line 6
At this point it's pointless to selecta collection.
I made sure that the user root has ReadWrite access and accessing the database with MongoDb Compass is working fine and shows all datbases/collections and lets me read/write data.
My Setup:
OS: Ubuntu 18.04
MongoDB Version: 3.6.3
PHP version: 8.0.3
MongoDB PHP Driver Version: 1.9.1
Apache2 is used to run the PHP code.
Now I found out that there is a Driver and a Library so after installing the Library everything seems to work now. I didn't know that the application was split into 2 parts.

Change max size of odbc_exec() return

I'm doing a procedure call to SQL Server from PHP ODBC. One of the fields on the procedure returns has a lot of text. The code runs with no erros, but the text read by odbc in my code comes incomplete.
$result = odbc_exec($db, "{CALL myprocedure(2, 3)}");
while(odbc_num_rows($result)) {
$m[] = odbc_fetch_array($result);
var_dump($m);
}
I got this return of var_dump($m):
array(1) { [0]=> array(1) { ["mensagem"]=> string(4096) "
I want change the max size that can get from a field with PHP ODBC. How I can do this from my code?
I don't have access to php.ini file on the server.
According to http://php.net/manual/en/odbc.configuration.php the only variable with 4096 is "odbc.defaultlrl". According to https://stackoverflow.com/a/4500598/4934937, ini_set("odbc.defaultlrl", "100K"); should do the trick.

Freeradius - Receive data from external script

I am using Freeradius v3 for my project, and I am executing an external php script to do some checks in the authorization section. What I am trying to achieve is to get multiple attribute-value pairs from the script like:
Auth-Type (control) : value Reply-Message (reply) : value ...
So, for example, i would like to receive and Auth-Type = Accept plus a Reply-Message from the script.
I used this post: FreeRadius Reading attributes while executing external script as reference, and I tried to do as suggested but it isn't working.
Here is some code to explain what I'm doing:
1 - Authorize section
authorize{
update{
control: += `/usr/bin/php -f /path/to/script/test.php '%{User-Name}'`
}
....
2 - Php script (echo section)
echo "Auth-Type = Accept,\n";
echo "reply:WISPr-Redirection-URL = http://google.com,\n";
echo "reply:Reply-Message = 'hello world'\n";
3 - Php output (as suggested from the linked post)
Auth-Type = Accept
reply:WISPr-Redirection-URL = http://google.com
reply:Reply-Message = 'hello world'
4 - Freeradius output
Proxying to virtual server test-server
(0) # Executing section authorize from file /etc/freeradius/sites-enabled/test-server
(0) authorize {
(0) update {
(0) Executing: /usr/bin/php -f /path/to/script/test.php '%{User-Name}':
(0) EXPAND %{User-Name}
(0) --> alice
(0) ERROR: Failed parsing output from: /usr/bin/php -f /home/saiv/radius_script/test.php '%{User-Name}': Expecting operator
(0) ERROR: Program returned code (0) and output 'Auth-Type = Accept, reply:WISPr-Redirection-URL = http://google.com, reply:Reply-Message = 'hello world''
(0) } # update = fail
(0) } # authorize = fail
If I remove the "reply:Reply-Message ..." and put only "Reply-Message:..." the output is accepted by freeradius but the Reply-Message avp goes under "control" and this is not correct.
(0) Program returned code (0) and output 'Auth-Type = Accept, WISPr-Redirection-URL = http://google.com, Reply-Message = 'hello world''
(0) control::Auth-Type = Accept
(0) control::WISPr-Redirection-URL = http://google.com
(0) control::Reply-Message = hello world
Can someone tell me what I am missing?
Any help would be appreciated.

PHP MongoDB inconsistent results with query on MongoDate

I'm running a very basic script on a sharded MongoDb setup to select the number of messages on a given day.
However, running this multiple times, results in inconsistent results, sometimes it returns the number, sometimes it just returns 0.
The mongodb server has version 2.4.3
Am I missing something here?
This is the script:
<?php
$mongo = new MongoClient("mongodb://127.0.0.1:27017");
$db = $mongo->selectDB('database');
$messages = $db->selectCollection('messages');
$date1 = new MongoDate(strtotime('2013-10-20'));
$date2 = new MongoDate(strtotime('2013-10-21'));
var_dump($date1);
var_dump($date2);
$iterator = $messages->find(array('date_replied' => array('$gte' => $date1, '$lt' => $date2)));
$count = $iterator->count();
var_dump($count);
And this is the result, 2 times ran directly after each other:
~$ php -f mongo.php
object(MongoDate)#4 (2) {
["sec"]=>
int(1382220000)
["usec"]=>
int(0)
}
object(MongoDate)#5 (2) {
["sec"]=>
int(1382306400)
["usec"]=>
int(0)
}
int(494921)
~$ php -f mongo.php
object(MongoDate)#4 (2) {
["sec"]=>
int(1382220000)
["usec"]=>
int(0)
}
object(MongoDate)#5 (2) {
["sec"]=>
int(1382306400)
["usec"]=>
int(0)
}
int(0)
Your database might be corrupt. Can you do a db.repairDatabase() and try again? It this fails try to re-create the index, I had similar issues with distributed collections.
Please keep in mind that repairing will block the whole database operations and might throw away any corrupted data. Proceed with care!

SOAP web service not recognizing ArrayOfAnyType from PHP client for Agemni Database API

I am trying to insert a lead into the SOAP web service with this WSDL: http://www.agemni.com/AgemniWebservices/service1.asmx?WSDL
The API is documented here: http://wiki.agemni.com/4Integration_And_API%27s/APIs/Database_API
This web service's back end code seems to be in .NET.
Here is my code:
// Create soap client.
try {
$this->client = new SoapClient("https://www.agemni.com/AgemniWebservices/service1.asmx?WSDL", array('soap_version' => SOAP_1_2, 'cache_wsdl' => 0, "trace" => true));
} catch (Exception $e) {
$this->logMessage('Couldn\'t connect to web service.');
throw $e;
}
// Create parameters.
$dataParams = new \stdClass;
$dataParams->strUsername = 'userman';
$dataParams->strPassword = 'hissecretpassword';
$dataParams->strCompanyName = 'validcompanyname';
$leadCode = 2;
$dataParams->objecttype = $leadCode;
// Create keys.
$dataParams->keys = new \stdClass;
$dataParams->keys->Phone = 'Phone';
// Create values.
$dataParams->values = new \stdClass;
$dataParams->values->Phone = '8011234567';
// Call web service.
$validateResult = $this->client->CreateEntity($dataParams);
Here is the response I receive:
object(stdClass)#27 (1) {
["ValidateEntityResult"]=>
object(SoapVar)#29 (4) {
["enc_type"]=>
int(0)
["enc_value"]=>
object(stdClass)#28 (10) {
["statusCode"]=>
string(9) "Succeeded"
["status"]=>
string(5) "Error"
["description"]=>
string(56) "Phone number is required and needs to be 10 digits long."
["errorNumber"]=>
int(1)
["xmlResult"]=>
string(39) "<?xml version="1.0" standalone="yes" ?>"
["EntityValidated"]=>
bool(false)
["EntityCreated"]=>
bool(false)
["EntityUpdated"]=>
bool(false)
["EntityIDCreated"]=>
int(0)
["isloggedIn"]=>
bool(false)
}
["enc_stype"]=>
string(15) "ExceptionReport"
["enc_ns"]=>
string(44) "http://tempuri.org/AgemniWebService/Service1"
}
}
I found a similar issue on PHPFreaks that was years old and was never successfully answered. I see other similar issues with nesting parameters in the PHP SoapClient, but all of the suggestions I've seen end in the same error message for me.
The authentication is being received just fine, along with the company name. However, I've stabbed at formatting, parsing, and encoding the keys and values parameters in nearly every way I could conceive. I've played with declaring my parameters as SoapVar and SoapParam with every potential constructor parameter I could think of and still have received the same error message.
I'd greatly appreciate any suggestions as to any reason that someone could suppose that the Agemni web service is not accepting my lead's phone number.
Thanks.
Update
I can just generate the XML request I need in a string and send it using cURL, but I'd like to use SoapClient. However, I have a hard time generating the elements within the keys and values nodes to look like this:
<anyType xsi:type="xsd:string">phone</anyType>'
I followed some guides on creating custom complex types in SoapClient, but I couldn't get it to create XML that looks like that.

Categories