I met a weied problem when installing phpredis by
cd phpredis && ./configure && make && make install
after that, I add
extension=redis.so
into php.ini.
I can get an OK by running
php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"
BUT when running http:127.0.0.1, nginx throw a error " Fatal error: Class 'Redis' not found in index.php"
<?php>
$client = new Redis();
<?>
I guess this may be some problems related with environment...
Thanks for any advice!
The command line probably does not use the same php.ini file than the web server.
Use phpinfo(); to know which configuration file is loaded in both cases and then declare your extension in the ini file used by your web server.
I had this issue minutes ago, and I solved it restarting the server, this way the server refresh *.ini files
If you're using composer and get the error "Class Redis not found" try put a backslash before the name class. Like this:
<?php
$client = new \Redis();
<?
Related
Normally I used file as driver to store session and cache. Now I want to work with Memcached to store session and cache on Laravel 5.7 application. It is new to me. I have already installed php-memcached on my local environment.
In my Laravel 5.7 web application I have configured session.driver and cache.default in the .env file as following.
SESSION_DRIVER=memcached
CACHE_DRIVER=memcached
I leave everything else with its default installation. When I refresh the page I get the following error.
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Class 'Memcached' not found
/vendor/laravel/framework/src/Illuminate/Cache/MemcachedConnector.php 69
I do understand that when you configure driver for session and cache config to use Memcached, the MemcachedConnector will get involved. It imports the Memcached class and tries to create an instance object of the Memcached class as following.
use Memcached;
class MemcachedConnector {
protected function createMemcachedInstance($connectionId) {
return empty($connectionId) ? new Memcached : new Memcached($connectionId);
}
}
With the above error, it seems like the Memcached class is missing. How can I solve it? Please do not tell me to do the following even it solves the problem.
SESSION_DRIVER=file
CACHE_DRIVER=file
or
SESSION_DRIVER=array
CACHE_DRIVER=array
Because I would like to use Memcached and would like to know what to do to make it work.
I can't comment yet so sorry for posting as answer.
Try running php -i || grep 'memcached' from your app directory.
If you're running vagrant, try vagrant ssh then php -i || grep 'memcached'
You could also (as suggested below) add phpinfo(); to the top of your routes/web.php (underneath the <?) and that should spit out your php info when you try to load your site in the browser.
This will clue you up as to whether or not memcached is installed and loaded or not.
I'm using PHP to try using the Google Cloud Spanner. I already did the gCloud settings and everything, and that's right. Now I need to make the connection via PHP to do a CRUD with the database that is in Spanner, but the code below always returns the error:
PHP Fatal error: Undefined constant 'Grpc\STATUS_UNKNOWN' in
/xxx/xxxx/www/vendor/google/cloud-spanner/Connection/Grpc.php on line
129
The code I have is:
<?php
require 'vendor/autoload.php';
use Google\Cloud\Spanner\SpannerClient;
/* Error start here */
$spanner = new SpannerClient([
'projectId' => 'my-project-id'
]);
$db = $spanner->connect('instance', 'database');
$userQuery = $db->execute('SELECT * FROM usuario WHERE login = #login', [
'parameters' => [
'login' => 'devteam'
]
]);
$user = $userQuery->rows()->current();
echo 'Hello ' . $user['login'];
The requirements I use in the composer are:
"require": {
"google/cloud": "^0.32.1",
"google/cloud-spanner": "^0.2.2"
}
I noticed that if I enter through the browser, the error presented above continues to appear. If I run the command php teste.php on the terminal, it runs the script correctly, ie, the terminal works and the browser does not.
Google Cloud PHP's spanner client is gRPC only. This means to use it you will need to install the gRPC PHP extension:
pecl install grpc
Once you have done that, add google/proto-client-php and google/gax to your composer.json and run composer update. After this is done, the error will be resolved.
For those wanting more detailed instructions, see this page for installing and enabling gRPC for PHP!
Since you mentioned that it works on CLI but not on browser, I can say that you need to enable the grpc extension on your php web server config.
E.g. Add
extension=grpc.so to your /etc/php/5.6/apache2/php.ini
This is a strange error that's constantly occurring.
Fatal error: Class 'Guzzle\Http\Client' not found in /home/futcoins/public_html/autobuyer/classes/shopify.php on line 15
This is the source code. I think this question is pretty straight forward and I've been stuck with this problem for a couple of days, any ideas?
use Guzzle\Http\Client;
use Guzzle\Plugin\Cookie\CookiePlugin;
use Guzzle\Plugin\Cookie\CookieJar\FileCookieJar;
class Shopify {
//initialise the class
public function __construct() {
}
public function GetOrders() {
$client = new Client(null); //Line 15 where errors occurs
$request = $client->get("url");
$response = $request->send();
$json = $response->json();
return $json;
}
}
So you have a declaration at the top
use Guzzle\Http\Client;
That means you either have an autoloader or have included the appropriate file(s) manually. So you need to find the file that has that class and include it or else PHP will be looking for code you've not given to it.
I'm not sure it is the right solution for you but I had the exact same problem and to fix it I updated composer on my server and regenerated the autoload file:
sudo /usr/bin/composer.phar self-update
/usr/bin/composer.phar dump-autoload
I'm not sure it is necessary but I also restarted apache:
sudo /etc/init.d/httpd restart
To prevent this in the future and because we are using Elastic Beanstalk I created an configuration file to make sure that composer is up to date:
commands:
01updateComposer:
command: export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update
option_settings:
- namespace: aws:elasticbeanstalk:application:environment
option_name: COMPOSER_HOME
value: /root
Source: http://blogs.aws.amazon.com/php/post/Tx2M04LCN1UEE0E/Reduce-Composer-Issues-on-Elastic-Beanstalk
I am trying to use the HttpRequest class which should be in the PECL_HTTP extension of php.
I have php5 and used the following to install pecl_http.
sudo pecl install pecl_http
pecl/pecl_http is already installed and is the same as the released version 2.0.1
install failed
After that i enter into my php.ini:
[PHP]
extension=http.so
[...]
Then i restart my apache2 server, and try using the HttpRequest class, but it gives me the following error:
PHP Fatal error: Class 'HttpRequest' not found
What are possible error's i might have missed?
UPDATE: (Changed the title)
The Extension is not shown in phpinfo(), i set
extension=http.so
And checked if the http.so file is in my extension_dir. I really don't know how to make php recognise the extension.
UPDATE 2:
I managed to install extension, but the class still does not exist.
For others, i had to reference the other extensions pecl_http needs. (For me: propro.so, raphfr.so)
UPDATE 3:
I did not manage to make the Class visible, the answers below show some approaches with other classes.
I solved this issue by using CURL.
You have installed the new version of the extension which uses a completely different API. I still don't know how it works, but I will update my answer one I know. The Documentation of the new version is to be found at http://devel-m6w6.rhcloud.com/mdref/http.
To Install the old version, first uninstall the new verion and then execute
pecl install http://pecl.php.net/get/pecl_http-1.7.6.tgz
UPDATE: here are two examples from the documentation, both should work well:
one request (can be found at http://devel-m6w6.rhcloud.com/mdref/http/Client/enqueue):
<?php
(new http\Client)->enqueue(new http\Client\Request("GET", "http://php.net"),
function(http\Client\Response $res) {
printf("%s returned %d\n", $res->getTransferInfo("effective_url"), $res->getResponseCode());
return true; // dequeue
})->send();
multiple requests (can be found at http://devel-m6w6.rhcloud.com/mdref/http/Client/once):
<?php
$client = new http\Client;
$client->enqueue(new http\Client\Request("HEAD", "http://php.net"));
$client->enqueue(new http\Client\Request("HEAD", "http://pecl.php.net"));
$client->enqueue(new http\Client\Request("HEAD", "http://pear.php.net"));
printf("Transfers ongoing");
while ($client->once()) {
// do something else here while the network transfers are busy
printf(".");
// and then call http\Client::wait() to wait for new input
$client->wait();
}
printf("\n");
while ($res = $client->getResponse()) {
printf("%s returned %d\n", $res->getTransferInfo("effective_url"),
$res->getResponseCode());
}
In both examples you can use $res->getBody() to return the body of the response.
I couldn't test these examples but I have heard of other people that they work.
I had the same problem and solved it by arrange the order in wich extensions are loaded in php.ini
All my other extensions was loaded using their own .ini files in /etc/php5/mods_available.
In my apache2 error.log I noticed that json_decode was needed by http.so to load.
I created a file for http (http.ini) and a symlink in /etc/php5/apache/conf.d with a higher prefix than json.
my http.ini
; configuration for php http module
; priority=50
extension=raphf.so
extension=propro.so
extension=http.so
use the new pecl_http.2.0.6 like this
new http\Message();
or extend in your own class as extends http\Message
I just wanted to take a look at Mongo-DB. But i just don't get it running. I've installed it with PECL and my phpinfo() tells me that the extension is loaded, but when i try to get a connection with
$mongo = new Mongo();
I get this:
Fatal error: Uncaught exception 'MongoConnectionException' with
message ': Transport endpoint is not connected'
Anybody have the same Problem? ... Or any Idea on this?
Please don't take this the wrong way, but have you actually got the server running? Only it looks like your error relates to a failure to connect and you've made no mention of the server or where it is located (localhost on the default port for example)
any server start method, such as "/etc/init.d/mongodb start" or "service start mongodb" will fail, if a stale lock file still exists. In Ubuntu/Debian this is /var/lib/mongodb/mongod.lock. Look for this and delte it, if it exists and seems to be an old one.
check out whether server is running or not..
/etc/init.d/mongodb start
then go to
root#kannan-desktop:~# mongo
MongoDB shell version: 1.6.3
connecting to: test
>
Don't forget to change the IP in your mongod.conf if it's a new installation.
custom string looks like that
mongodb://username:password#host:port/database
First Change the Default db path by following command
$ sudo mkdir -p /data/db/
$ sudo chown id -u /data/db
and then the final command is..
$ mongod --journal
Do not close terminal until you are working with mongoDB
It works for me...
just write mongod in your terminal and will work well