Why do I get slaveOkay = 0; Timeout = 30000 MongoPHP - php

I am using Mac, netbeans, x-debug, with Mongo PHP. I am trying to run a basic search like:
$results = $mongo->$col->find();
However during debug, the value for $results is slaveOkay = 0 and timeout = 30000. Why is this so? Some version information about the tools installed are:
PHP 5.4.20 (cli) (built: Sep 24 2013 10:10:10) (DEBUG) Copyright (c)
1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013
Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
MongoDB shell version: 2.4.6
Thanks.

Where does that $col variable come from?
And where does $mongo come from?
The correct way to query a collection is
<?php
$mongo = new MongoClient(...);
$collection = $mongo->databaseName->collectionName;
$results = $collection->find();
?>
Then you can iterate over $results like so:
foreach($results as $document) {
/* Do something with $document */
}
See http://php.net/mongocollection.find and http://php.net/mongo.queries for more details

Related

Laravel JSON maxCDN / Chrome JSON Formatter does not work

Currently i am working with Laravel and the maxcdn API.
This is my very little test code
Route::get('cdn', function() {
$api = new MaxCDN("myurl","mykey","mysecret");
$data = $api->get('/account.json');
return response()->json($data);
});
The header is set to json as you see
application/json
Now if i visit my /cdn url the Chrome JSON Formatter should be of course formate the output. But it does not work, i only get this output
"{\"code\":200,\"data\":{\"account\":{\"id\":\"12312\",\"name\":\"My Name \",\"alias\":\"myurl\",\"date_created\":\"2015-05-17 07:51:50\",\"date_updated\":\"0000-00-00 ........
I am working on my homestead machine
php -v
PHP 5.6.6-1+deb.sury.org~utopic+1 (cli) (built: Feb 20 2015 11:25:37)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
The $api->get('/account.json'); call returns a string that contains the json data. You are then passing this string to the response()->json(); method, and that is the output you are seeing.
You need to run the string through json_decode() in order to convert the json string into a PHP object. Once you do that, you can pass that result to the response()->json(); method, and you will get the result you're looking for.
Route::get('cdn', function() {
$api = new MaxCDN("myurl","mykey","mysecret");
$stringData = $api->get('/account.json');
// convert the json string into an actual PHP object
$data = json_decode($stringData);
// respond with the object
return response()->json($data);
});

PhP touch on non existing file returns true

i have a function wich makes a check if a folder is writable. but when i try to use the php touch variable in it like this
public function isFileServerMounted()
{
$config = $this->getServiceLocator()->get('config');
$storageDir = $config['xxx']['xxx']['xxx'];
$mountCheckFile = $config['xxx']['xxx']['xxxx'];
// we are using a simple file check as indication if we are mounted
return touch($storageDir . DIRECTORY_SEPARATOR . $mountCheckFile);
}
The function always returns true, regardles if the file i am checking is there or not. i checked the paths and they are correct and i can acess the file via nano over schiell.
The touch comand always returns true, regardles if i delete or make the mount check file.
Anyone has any idea why?
I am using:
PHP 5.3.3-7+squeeze19 with Suhosin-Patch (cli) (built: Feb 17 2014 10:10:23)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
OS:
Distributor ID: Debian
Description: Debian GNU/Linux 6.0.3 (squeeze)
Release: 6.0.3
Codename: squeeze
touch() is to sets access and modification time of file.
If the file does not exist, it will be created.
Maybe you can use file_exists like this:
$filename = $storageDir . DIRECTORY_SEPARATOR . $mountCheckFile;
if (!file_exists($filename))
return false;
return touch($filename);

PHP file_get_contents not working correctly

I asked a question on here yesterday and was given the following code.
<?php
function usd_rate(){
$json = file_get_contents("https://bitpay.com/api/rates");
$obj = json_decode($json);
if($obj->code == 'USD') return $o->rate;
}
echo usd_rate()
?>
It worked fine at first, but I left my shared hosting and moved to a dedicated server host.
I have checked the PHP.ini to ensure the below
; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-fopen
allow_url_fopen = On
; Whether to allow include/require to open URLs (like http:// or ftp://) as fil$
; http://php.net/allow-url-include
allow_url_include = On
but it still doesnt show any of the values. I have been stuck on this for about 2 hours now so I thought it might be a wise idea to ask for help.
Thanks for any you can provide me.
Also
Output of php --version
PHP 5.5.9-1ubuntu4.4 (cli) (built: Sep 4 2014 06:56:34)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
Not sure what my last host was running
there is error in code u have given try this code
function usd_rate(){
$json = file_get_contents("https://bitpay.com/api/rates");
$obj = json_decode($json);
foreach($obj as $o)
if($o->code == 'USD') return $o->rate;
}
echo usd_rate();

PhP shell execute ignores Exceptions

I have the strangest bug. I was like wtf^12.
I have a script wchich calls following function:
function checkNewFilename($newFilename)
{
if (file_exists($newFilename)) {
if (!unlink($newFilename)) {
debugDeploy($newFilename . ' already exists and could not be deleted.');
throw new Exception($newFilename . ' already exists and could not be deleted.');
}
}
}
It gets used like this:
$newFilename = $defaultConfig . DIRECTORY_SEPARATOR . 'client.xml';
checkNewFilename($newFilename);
echo 'wtf is happening here';
copy($configFilename, $newFilename);
Now when i run this code with normall browser/xdebug i get a cachable fatal error as it should be. BUT when i run the script via shell on
php script.php param param param
Somthing nuts happens. IT ignores the exceptions and gous as nothing happend. I get the error before the exception AND the echo after the function call... wth.
I am runing on
PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli) (built: Aug 6 2012
14:18:06) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0,
Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
Anyone has any idea what causes this strange behavior?

Laravel Route: Controller method not found

I took a copy of my live Laravel 4 app and set it up on an AWS Ubuntu instance.
Here's the same route that works on live site, http://pixcel.com/archivecloud/786531 ,
and the same route with same code (I think) on the EC2 instance
54.186.47.148/archivecloud/786531
Error returned is: Controller method not found
Live site:
PHP 5.3.27 (cli) (built: Feb 21 2014 07:53:29)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd., and
with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
Apache: not sure, it's shared hosting with site5
EC2:
PHP 5.4.25-1+sury.org~precise+2 (cli) (built: Feb 12 2014 10:45:30)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
Server version: Apache/2.2.22 (Ubuntu)
Relevant code:
Route LIVE:
Route::get('archivecloud/{id}', 'CloudHomeController#embed');
Route EC2: Route::get('archivecloud/{id}', 'CloudHomeController#embed');
Controller LIVE:
class CloudHomeController extends CloudBaseController {
public function embed($id){
$result = CloudFilm::getInstance()->getFilmByEmbedId($id);
$cliptype = "film";
}}
Controller EC2:
class CloudHomeController extends CloudBaseController {
public function embed($id){
$result = CloudFilm::getInstance()->getFilmByEmbedId($id);
$cliptype = "film";
}}
Looks like the Environment variables are empty. Will look this up.

Categories