I have been trying to implement memcached in my application built in fat free framework. I have read that it should be explicitly defined as "memcached=192.168.--.---:11211" but no matter how I implement it, it uses "folder=tmp/cache/"
Tried and failed approaches
config.ini
CACHE="memcached=192.168.--.---:11211"
index.php
$f3->config('config/config.ini');
$f3->run();
code
$cache = \Cache::instance();
var_dump($cache);
Output
Object(Cache)#7 (3) {
["dsn":protected] => string(17)"folder=tmp/cache/"
["prefix":protected] => string(12)"randomString"
["ref":protected] => NULL
}
code
$cache = \Cache::instance();
$cache->load("memcached=192.168.--.---:11211");
var_dump($cache);
Output
Object(Cache)#7 (3) {
["dsn":protected] => string(17)"folder=tmp/cache/"
["prefix":protected] => string(12)"randomString"
["ref":protected] => NULL
}
code
$cache = new Cache("memcached=192.168.--.---:11211");
var_dump($cache);
Output
Object(Cache)#7 (3) {
["dsn":protected] => string(17)"folder=tmp/cache/"
["prefix":protected] => string(12)"randomString"
["ref":protected] => NULL
}
index.php
$f3->config('config/config.ini');
$f3->set('CACHE',"memcached=192.168.--.---:11211");
var_dump($f3->get('CACHE'));
Output
string(17)"folder=tmp/cache/"
What am I missing?
Do you have installed the proper php extension? Or is the connection secured? Because when there’s an error, the cache engine will just fall back to folder mode.
Related
I have several WordPress sites hosted in my server, and some of them have the W3 Total Cache plugin installed. Right now I flush the cache for each site manually, but I want to do it programatically and all together.
I'm trying to write a PHP script that will do this. I was looking at the code used by the "Clean Cache All" option for this plugin in the dashboard, and is this piece here:
if ( $modules->plugin_is_enabled() ) {
$menu_items['10010.generic'] = array(
'id' => 'w3tc_flush_all',
'parent' => 'w3tc',
'title' => __( 'Purge All Caches', 'w3-total-cache' ),
'href' => wp_nonce_url( network_admin_url(
'admin.php?page=w3tc_dashboard&w3tc_flush_all' ),
'w3tc' ));
So I'm guessing there are 2 ways to do what I need:
1- Make a web request, but that would probably require authentication.
2- Instance the class and use the method w3tc_flush_all();
This is what I have thus far:
function clean_cache($web)
{
global $path;
$path2 = $path.$web["directory"]."/httpdocs/wp-content/plugins/w3-total-cache/";
if(file_exists($path2)) //Tienen TotalCache instalado
{
require_once $path.'w3-total-cache-api.php';
//if(class_exists("w3-total-cache-api.php"))
//{
$plugin_totalcache = & w3_instance("w3-total-cache-api.php");
//if(function_exists('w3tc_dbcache_flush'))
$plugin_totalcache->w3tc_fush_all();
//}
}
}
Any help will be much appreciated.
I am trying to add a Captcha as part of a big application form.
Getting the following error:
session has already been started by session.auto-start or session_start()
How can I get around this as behind the scenes it uses:
// Process metadata specific only to this namespace.
Zend_Session::start(true); // attempt auto-start (throws exception if strict option set)
I instantiate it in the Controller:
$this->view->captcha = new Zend_Form_Element_Captcha('captcha', array(
'captcha' => array(
'captcha' => 'Figlet',
'wordLen' => 6,
'width' => 300,
'height' => 100,
)
)
);
In the View:
<?php echo $this->captcha; ?>
I can't tamper with current session as it holds a lot of information. Is there a workaround?
Help would be appreciated.
You can do one thing in this case, try starting your Zend session in bootstrap file in below way and set that session object in registry:
protected function _initSession() {
$userSession = new Zend_Session_Namespace('user_session');
Zend_Registry::set('userSession', $userSession);
}
After this you will be able to get session object anywhere from registry.
$userSession = Zend_Registry::get('userSession');
Since you will start your Zend Session before session_start() so it might not produce any error.
I'm having serious trouble to solve this issue. I got an APP with 3 modules that got different services to provide by SOAP. What happens is that 2 of them are getting this response:
SoapFault
File:
/var/www/empreendimentos/vendor/zendframework/zendframework/library/Zend/Soap/Client.php:10
Message:
Procedure not present
I already double checked, and the names of the functions are right and I use the method getFunctions. This is the return from getFunctions():
array
0 => string 'Array getCliAll(anyType $filter)' (length=32)
1 => string 'Array insertCli(anyType $data)' (length=30)
2 => string 'Array editCli(anyType $data, anyType $id)' (length=41)
3 => string 'void setServiceLocator(anyType $serviceLocator)' (length=47)
4 => string 'void getServiceLocator()' (length=24)
My handle methods look like this:
public function handleWSDL() {
$autodiscover = new AutoDiscover();
$autodiscover->setClass('\Cli\Service\CliService');
$autodiscover->setUri($this->_URI);
$wsdl = $autodiscover->generate();
$wsdl = $wsdl->toDomDocument();
// geramos o XML dando um echo no $wsdl->saveXML()
echo $wsdl->saveXML();
}
public function handleSOAP() {
$soap = new \Zend\Soap\Server($this->_WSDL_URI);
$soap->setWSDLCache(false);
$classHandle = new CliService();
$classHandle->setServiceLocator($this->getServiceLocator());
$soap->setClass($classHandle);
$soap->handle();
}
I get no errors on the server side. Only this response for all the methods. What is wrong?
UPDATE:
Turns out it's a "Problem" of the ZF2 config. overload. I had my modile.config.php to hold my WSDL and URI information, but used the same label for the config on the file. The overload was making every WSDL and URI the same, and giving me the problem.
Like this:
Emp Module modile.config.php
'service_url' => array(
"wsdl" => 'http://localhost/empreendimentos/public/emp/service?wsdl',
"return" => 'http://localhost/empreendimentos/public/emp/service',
),
Emp Module modile.config.php
'service_url' => array(
"wsdl" => 'http://localhost/empreendimentos/public/cli/service?wsdl',
"return" => 'http://localhost/empreendimentos/public/cli/service',
),
Anyone know why this is like this? is it suposed to mix module configs?
Had this problem yesterday, found the answer was in the server wsdl call.
The server calls its own wsdl to introspect the available methods. If your wsdl url is wrong, it sees what methods are available in another server and says 'Procedure not present'.
In my case the AdmintoolsController had the line
$wsdl_url = 'http://' . $_SERVER['HTTP_HOST'] . '/news/?wsdl';
so it was looking in the News service for the method.
Change it to
$wsdl_url = 'http://' . $_SERVER['HTTP_HOST'] . '/admintools/?wsdl';
and it works fine.
I searched Google for hours looking for this fix, and my colleague looked at the code and spotted it straight away.
Hope this helps
John
Also try to do the below changes and then check if it works:
Remove the files starting with "wsdl-" in the tmp folder of your zend server.
Make a php setting: phpSettings.soap.wsdl_cache_enabled = 0 in your application.ini file.
i wanted to know in which file we can set common code, for example i wanted to set timezone to UTC, instead of putting same code in all controllers file is there any way to put the code once and it will be reflect in all files.
You may create your file in ''components'' folder. You can see this folder in "protected" folder.
Or you can write your code in controller.php
File path: webroot/protected/components/Controller.php
Can you please try to add the codes in bootstrap.php file
If you need to set the server time you can check here.It is a simple method
Change time zone
Use application params, ie:
// config part
return array(
// ...
'params' => array(
'myParam' => 123
)
// ...
);
// Then in app use
Yii::app()->params['myParam'] // Will return 123
You can also create your own params holder as component, ie:
// config part
'components' => array(
'myConfigs' => array(
'class' => 'ext.MyConfigs'
'myParam1' => 123,
'myParam2' => 'blah'
)
)
// Component in extensions
class MyConfigs extends CComponent
{
public $myParam1;
public $myParam2 = 'defaultValue';
}
// Then in app use it:
Yii::app()->myConfigs->myParam1 // will return 123
I would like to protect a directory and authenticate users against a mysql database. I am using lighttpd and haven't been able to find a way of doing so. Is it possible?
You could use mod_auth, here is the relevant doc page
Since it has no direct access to a database, i would recommend using the 'htdigest' method, and regenerating the file from your database users.
the 'htdigest' format is just: "user:realm:md5(password)", as explained in the page.
Generating a file like this from a php script should be extremely simple.
pseudo-code:
foreach ($users as $user) {
// $user['md5pass'] = md5($user['password']);
$line = sprintf("%s:%s:%s\n", $user['username'], 'protected', $user['md5pass']);
file_put_contents('htdigest-file', $line, FILE_APPEND);
}
Also, from the same page, here is a sample lighttpd configuration for mod_auth:
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "lighttpd-htdigest.user"
auth.require = ( "/download/" =>
(
# method must be either basic or digest
"method" => "digest",
"realm" => "download archiv",
"require" => "user=agent007|user=agent008"
),
"/server-info" =>
(
# limit access to server information
"method" => "digest",
"realm" => "download archiv",
"require" => "valid-user"
)
)