Getting an error in php5.6 not in php5.5 - php

I'm trying to get a phpdaemon running on ubuntu 16.04 with php5.6.
It runs on ubuntu 1404 with php5.5.9. I tried google of course but I don't know php code at all.
This is the error I'm getting:
PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /../../Service.php on line 79
This is the the actual code on line 79 an a bit below:
if(array_key_exists("session_id", $createSession)) {
// Session ID.
$sessionId = $createSession["session_id"];
Would be great if someone could help me out.
EDIT:
thanks for the quick replies. someone asked for the $createsession. I think this is it, but I am not sure.
still, I'm not sure why it runs on the old version.
// Create and invoke.
$createSession = $this->call_service(P_XMLRPC_URL, "create_session", array(
"requester" => $sale['prkcode'] . '#' . $sale['pdcode'],
"service" => P_SERVICE,
"version" => P_VERSION,
"invoke" => array(
"method" => PRM_INVOKE_METHOD,
"parameters" => array(
"tickets" => array(
$ticket
)
)
)
));

Related

How do I use response from an API into the controller - CodeIgniter

I tried to integrate an API that built-in laravel and now I have to use that API's response into the Codeigniter project, I'm developing a Codeigniter project(I'm not familiar with this framework and it's my first time working with this),
I finally could do it, I'm getting a response from an API
$result = curl_exec($response);
$rs=json_decode($result,true); print_r($rs);
return $rs;
Array(
[user] =>
Array(
[user_no] => PMRQ3fVd6eGEvd5aO9MDJg()() [name] => Anthony [middle_name] => S [lastname] => Mosteller [email] => AnthonyMosteller#test.net
)
)
and desperately trying to access the object full name, email, and user_no into my controller
But I am stuck now.
controller code:
$user=$this->userapi->userapicall($user_url,$token);
$this->session->set_userdata('username',$user['name']); // here want to use full name (name+middle_name+lastname)
$this->session->set_userdata('useremail',$user['email']);
I'm getting an error for name and email
A PHP Error was encountered
Severity: Notice
Message: Undefined index: name
Filename: controllers/auth.php
Line Number: 106
Do I need to create for each loop or seems something really silly mistake I make
I would appreciate an example of this.
$rs = json_decode($result,true); print_r($rs);
Here you are getting a multidimensional array. As per your code sample it looks like -
$rs = ['user' => ['user_no' => 'PMRQ3fVd6eGEvd5aO9MDJg', 'name' => 'Anthony', 'middle_name' => 'S', 'lastname' => 'Mosteller', 'email' => 'AnthonyMosteller#test.net']];
So if are trying to access user's name in controller -
$this->session->set_userdata('username',$user['user]['name']);
This should fix the problem. Also you should check if you are getting success status from API.

PHP::MongoCollection->aggregate alternative or fix

I'm using xhgui and getting this error:
127.0.0.1:27017: no such cmd: aggregate
Stack trace:
/var/www/profiler/src/Xhgui/Profiles.php(172): MongoCollection->aggregate(Array)
Code:
$mongo = new MongoClient($config['db.host'], $config['db.options']);
$db = $mongo->$config['db.db'];
$results = $db->results->aggregate(array(
array('$match' => $match),
array(
'$project' => array(
'date' => $col,
'profile.main()' => 1
)
)
));
Is it possible to fix this error? Maybe need to update mongo extension OR is there any other alternative way?
This appears to actually be a problem with your MongoDB instance itself. Aggregation was introduced in version 2.2 of MongoDB, so if your server is running an older version, it won't understand the aggregate() command.
https://docs.mongodb.org/manual/core/aggregation-introduction/

PHP Soap - SOAP-ERROR: Encoding: object hasn't 'checkConnectivityRequest' property

I'm having a problem getting a particular SOAP call to work -most of them work fine, but this one is giving me a headache.
The WSDL is http://fibre.venus.ispwebhost.com/FibreClassTest/colt.wsdl, and the request I am generating is:
$result = $soap->checkConnectivity(
array('checkConnectivityRequest' =>
array(
'requestType' => 'SITE',
'requestMode' => array(
'requestId' => date("Ymdhis"),
'siteAddress' => array(
'postalZipCode' => $this->postcode,
'connectivityType' => 'COLT FIBRE',
'bandwidth' => '2M',
),
)
)
)
);
However I'm getting a SOAP error back (which I believe means it's not even passing it to the web service), so not sure if I'm mis-reading the WSDL?
Thanks!
If you search in the content of http://fibre.venus.ispwebhost.com/FibreClassTest/colt.wsdl you will notice that there is not wsdl:operation named checkConnectivityRequest. The closest i saw was checkConnectivity so, try to replace checkConnectivityRequest with checkConnectivity and let me know.
Happy coding

MongoDB aggregation does not work (or is very slow) with PHP and works perfectly in shell?

I'm trying to use the aggregate method on my collection (containing more than 20M documents).
I first tried it in the Windows shell :
db.data.aggregate([
{$match: {firstname: "Roger"}},
{$group:{"_id":"$id_car",count:{$sum: 1}}},
{$sort: {count: -1}},
{$limit: 50}])
And it works perfectly, returning the results after a few seconds.
When I "translate" it in PHP :
$data = $db->data;
$ops = array(
array(
'$match' => array(
'firstname' => 'Roger'
)
),
array(
'$group' => array(
'_id' => '$id_car',
'count' => array(
'$sum' => 1
)
)
),
array(
'$sort' => array(
'count' => -1
)
),
array(
'$limit' => 4
)
);
$res = $data->aggregate($ops);
I get a timeout PHP Fatal error :
Uncaught exception 'MongoCursorTimeoutException' with message 'localhost:27017: cursor timed out (timeout: 30000, time left: 30:0, status: 0)'
I don't know if I've made a mistake in my PHP code, or if aggregate is supposed to be much slower in PHP than in shell ?
Also, I have added an index on "firstname" field to make the query go faster.
By the way, is there any way to set the timeout to infinity for this kind of call ?
Thanks a lot for your help !
Joe
I don't really know about your issue (PHP being slower than the MongoShell), but something I've done that allowed me to run an aggregation in PHP (due to the timeout problems) is changing the way I invoked the aggregation.
Hope this helps someone that reaches this page because of the timeout problems, like I did!
Instead of $data->aggregate($ops) I ran the following equivalent to your case:
$db->command(
array('aggregate' => 'data', 'pipeline' => $ops),
array('timeout' => 100000000)
)
Notice that you must run the command over the $db and not your collection.

CActiveDataProvider not resolving params in criteria

I'm following along with Agile Web Application Development with Yii 1.1 and PHP5, working on the "TrackStar" project. For the life of me I can't understand where my problem is.
I'm getting the Exception:
CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined. The SQL statement executed was: SELECT COUNT(*) FROM tbl_issue t WHERE project_id=:projectId
It appears (to this noob's interpretation) that the params in my CActiveDataProvider is some how not resolving in the criteria as in the view:
(in /protected/controllers/ProjectController.php)
55 public function actionView()
56 {
57 $issueDataProvider = new CActiveDataProvider('Issue', array(
58 'criteria' => array(
59 'condition' => 'project_id=:projectId',
60 'params' => array(':projectId=' => $this->loadModel()->id),
61 ),
62 'pagination' => array(
63 'pageSize' => 1,
64 ),
65 ));
66 $this->render('view',array(
67 'model'=>$this->loadModel(),
68 'issueDataProvider' => $issueDataProvider,
69 ));
70 }
I checked my code against a github repo and I couldn't find any differences anywhere.
Is there something straightforward I'm missing here without having to post all of my code (and have somebody actually look through it)?
It looks you have an error in params of your criteria. (= after :projectId).
Right statement is
'params' => array(':projectId' => $this->loadModel()->id),
Params array is list of query parameter values indexed by parameter placeholders. For example, array(':name'=>'Dan', ':age'=>'31').

Categories