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.
Related
I'm trying to use multiple consumers with the same Redis transport using the Symfony Messenger component.
As mentioned in the Symfony guide, we can have problems if we use the same values for stream/group/messenger, cause the same message can be handled by multiple consumers.
So I have updated my supervisor config as follow:
environment=MESSENGER_CONSUMER_NAME=%(program_name)s_%(process_num)02d
Then, I have updated my messenger.yaml file as follow:
redis:
dsn: '%env(MESSENGER_TRANSPORT_REDIS)%'
options:
consumer: '%env(MESSENGER_CONSUMER_NAME)%'
I have reloaded the supervisor:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start messenger-consume:*
but I still get the error:
[2021-12-25T18:33:08.954217+01:00] console.CRITICAL: Error thrown while running command "messenger-dispatcher --count=100". Message: "Environment variable not found: "MESSENGER_CONSUMER_NAME"." {"exception":"[object] (Symfony\\Component\\DependencyInjection\\Exception\\EnvNotFoundException(code: 0): Environment variable not found: \"MESSENGER_CONSUMER_NAME\". at /var/www/vendor/symfony/dependency-injection/EnvVarProcessor.php:172)","command":"messenger-dispatcher --count=100","message":"Environment variable not found: \"MESSENGER_CONSUMER_NAME\"."} []
I follow the guidelines but there is something missing somewhere ... but where?
Why does my app not read env var?
If I call my consumer:
MESSENGER_CONSUMER_NAME=myconsumer ./bin/console messenger:consume redis
it works as expected; it does not work only with supervisor vars.
Thanks in advance
UPDATE
This is the complete section config of my supervisor file:
[program:consumer-redis]
command=php /var/www/bin/console messenger:consume redis --limit=5 --time-limit=3600
user=root
numprocs=6
startsecs=0
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d
environment=MESSENGER_CONSUMER_NAME=%(program_name)s_%(process_num)02d
Today I had a similar issue, but you need to explain a little more if my answer match with your problem if not please replay me to delete my answer.
So the problem is, when you run the command:
php /var/www/bin/console messenger:consume redis
Symfony asumes the APP_ENV from 2 parts, if you are using a web server, the variable is taken from the apache or nginx or php/apache.conf file configuration, but in command line if you server has no configured the variable APP_ENV, symfony is going to check the .env file and then .env.local or .env.local.php, so, if that variable doesn't exists, Symfony is not going to take any files like .env.prod.local or .env.prod because is missing that variable. If you are using
I found the answer thanks to this article.
Your configuration is all good. You simply need to add an environment variable with a default value, so that Symfony doesn't generate errors :
# .env.local
MESSENGER_CONSUMER_NAME=0
This env variable will be overwritten in processes ran by supervisor. To test it, I simply log $_ENV['MESSENGER_CONSUMER_NAME'] in a function. Here's what I get when I call it :
Not using Messenger (synchronously) : 0
Using Messenger : either messenger-consume_00 or messenger-consume_01. (In my config I have numprocs=2)
I fixed this problem by adding the following at the top of my config/packages/messenger.yaml file:
parameters:
env(MESSENGER_CONSUMER_NAME): '00'
I have created a number of selenium IDE files that I converted to phpunit format in Firefox IDE 2.9.1.1 (on a Windows box), using Options -> Format converter. Those converted files define a class "Example" that is derived from class PHPUnit_Extensions_SeleniumTestCase. I now know that this class needs to be changed to PHPUnit_Extensions_Selenium2TestCase. The problem is, I cannot get this to run with recent versions of phpunit.
I am running these tests on a Fedora 24 VM which is using php 5.6.30, java 1.8.0_121-b14, and firefox 51.0.1-2. I have tried to get these to run using selenium standalone server 3.0.1 (and now 3.1.0), and phpunit 5.7.13. I have the latest php facebook WebDriver installed. The error I keep getting is that the above mentioned class is not found. I did a grep on that class and this is what I found:
[root#localhost bin]# grep -r "PHPUnit_Extensions_Selenium2TestCase" .
Binary file ./phpunit/phpunit-4.6.7.phar matches
Binary file ./phpunit/phpunit-4.7.6.phar matches
So, it appears that this class does not exist in phpunit 5.7 and above (which are in that directory), nor does it exist in html-runner.phar, which is in the same directory. The seleniumhq.org site says to use html runner if you convert from IDE, but I can find no examples of how to use the html-runner.phar file (and no documentation).
Can someone please tell me what I should change the class name to, to get this test to work?
UPDATE:
I now know that if I want to use phpunit and selenium server to drive a firefox browser, I have to get selenium talking to geckodriver. I have installed:
geckodriver 0.14.0 at /usr/local/bin/geckodriver
selenium server 3.0.1 at /usr/local/bin/selenium
phpunit-5.7.13.phar installed at /usr/local/bin/phpunit
I used composer to add webdrivers (facebook 1.3.0 :
[root#localhost composer]# cat composer.json
{
"require": {
"facebook/webdriver": "^1.3",
"phpunit/phpunit": ">=3.7",
"phpunit/phpunit-selenium": ">=1.2"
}
}
php composer.phar install
They were added to the PATH:
[bjt#localhost projects]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/bin/selenium:/usr/local/bin/phpunit:/usr/local/bin/composer:/usr/local/bin/geckodriver
I have a small test file:
?php
require_once('/usr/local/bin/composer/vendor/autoload.php');
class test extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser("*firefox");
$this->setBrowserUrl("https://fakeurl.com/");
}
public function testMyTestCase()
{
$this->open("/");
}
}
Starting the selenium server:
java -jar /usr/local/bin/selenium/selenium-standalone-3.0.1.jar
When I run the test:
/usr/local/bin/phpunit/phpunit-5.7.13.phar --verbose test.php
Yields this error:
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: The best matching driver provider Firefox/Marionette driver can't create a new driver instance for Capabilities [{browserName=*firefox}]
So, it appears that geckodriver is not talking to selenium server. If I try to force the issue by changing the execution of the server:
java -Dwebdriver.gecko.driver="/usr/local/bin/geckodriver/geckodriver" -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar
or
sudo java -Dwebdriver.gecko.driver="/usr/local/bin/geckodriver/geckodriver" -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar
It makes no difference. I'm hoping someone can point out what I am missing. I'm at a dead end.
I am currently working through the same process of getting this to work and would like to point out a few things:
htmlrunner is meant to run the test cases saved directly from the Selenium IDE in the default format, which is html.
Make sure you can run firefox from the terminal running the selenium server.
You added two different selenium php bindings. The facebook one and the phpunit-selenium. I currently have it working with only the facebook binding and phpunit extending the class PHPUnit_Framework_TestCase. I would recommend using the example provided within github for facebook/webdriver without phpunit to verify that your selenium config is working, then add phpunit.
I tried to delete a bundle manually, but an error appeared...
I guess I forgot an essential edition, but I don't know what.
I deleted the file of that bundle, I delete its line in the AppKernel, and I deleted it's lines in the app/routing.yml.
Here is the error :
FileLoaderLoadException in FileLoader.php line 118:
Bundle "DbToYmlBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? in #DbToYmlBundle/Resources/config/services.yml (which is being imported from "/opt/lampp/htdocs/dublin/app/config/config.yml"). Make sure the "DbToYmlBundle" bundle is correctly registered and loaded in the application kernel class. If the bundle is registered, make sure the bundle path "#DbToYmlBundle/Resources/config/services.yml" is not empty.
Could someone help to find what is wrong ?
The error message states that the #DbToYmlBundle/Resources/config/services.yml is imported from /opt/lampp/htdocs/dublin/app/config/config.yml
Please check your config.yml's or provide some more information/codes, maybe the output for your prod.log /opt/lampp/htdocs/dublin/app/logs/prod.log
You can try to clear the cache with the console.
For the Dev environment:
php bin/console cache:clear
And for production environment :
php bin/console cache:clear --env=prod
I was trying to access http://localhost:8000/phpmyadmin for database in laravel. But it's showing the following error:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Open:
C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php
$others = $this->checkForAlternateVerbs($request);
if (count($others) > 0) {
return $this->getOtherMethodsRoute($request, $others);
}
throw new NotFoundHttpException;
I used following command to open my server and it automatically open with 8000 port that's why i have to use
http://localhost:8000/phpmyadmin
php artisan serve
So, if anyone know the solution, please reply.
If you have phpmyadmin properly installed and configured on your local, you should just access it from http://localhost/phpmyadmin with or without your laravel application running on http://localhost:8000, that make no difference.
Also, every URI you will try tro access after http://localhost:8000/ will be considered as a route of your laravel application.
Access http://localhost:8000/phpmyadmin involves you have a route like Route::get('/phpmyadmin', /** ... /*);
If you doesn't have phpmyadmin installed and accessible on your local, download it and follow the instructions to make it accessible from your web server.
The php artisan serve command run the PHP built-in server.
It doesn't use your apache (XAMPP) webserver, but the web server provided by php.
See PHP built-in server
Make sure you have a route setup for phpmyadmin in your routes.php
Route::get('/phpmyadmin', function () {
return 'Nothing here';
});
This will not give you the phpmyadmin though.
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();
<?