Fatal error: Class 'Memcache' not found in Zend Framework + Wamp - php

I have following code :
in application.ini
cache.default.adapter = "memcached"
cache.default.params.host = "localhost"
cache.default.params.port = "11211"
in Bootstrap.php
$cache = new Memcache();
$cache->connect($cache_params['host'], $cache_params['port']);
Zend_Registry::set("cache", $cache);
and also I am having memcache installed on my machine by putting php_memcache.dll in wamp\bin\php\php5.3.9\ext and also extension=php_memcache.dll in php.ini
But still I am getting the following error :
( ! ) Fatal error: Class 'Memcache' not found in \wamp\www\projectname\application\Bootstrap.php on line 160
I have gone through google but still not able to solved the problem. What is the problem why it's not connecting to the memcache.

You are trying to cache your database?
You want to use Zend_Cache.
(From: http://zendcoding.com/how-to-use-memcached-in-the-zend-framework)
$frontendOpts = array(
'caching' => true,
'lifetime' => 1800, //how long in seconds to keep the cache for.
'automatic_serialization' => true //In order to store objects and arrays, Zend must first serialize data into a string. If this parameter is set to ‘true‘, this serialization will happen on the fly and behind the scenes.
);
$backendOpts = array(
'servers' =>array(
array(
'host' => $cache_params['host'],
'port' => $cache_params['port'],
'weight' => 1
)
),
'compression' => false
);
$cache = Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts);
This link also demonstrates how to load and update the cache, and how to make it accessible from everywhere in your application. A good read, to be sure.

Your setting is memcached
cache.default.adapter = "memcached"
but you want to use memcache
$cache = new Memcache();
Try this example
<?php
$mc = new Memcached('mc');
$mc->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
if (!count($mc->getServerList())) {
$mc->addServers(array(
array('127.0.0.1',11211),
array('127.0.0.1',11211),
));
}
$key = 'mykey';
$mc->add($key,'test for memcached not memcache');
$val = $mc->get($key);
echo $val;
?>

Related

SoapClient call works on PHP 5.6 but not on PHP 7

I have a soapClient call that works fine with PHP 5.6 (RH6). We are upgrading the system to PHP 7 (RH7 with the same configuration as the previous one) but the same call does not work.
This is my code
$wsdlUrl = "https://THE_URL_I_AM_CALLING/repository/soap/2.1?wsdl";
$sslClientCert = "../../app/config/ssl/ssl_cert.crt";
$sslClientKey = "../../app/config/ssl/ssl_cert.key";
$proxy = 'proxy_http';
$port = 8080;
$contextOptions = [
'ssl' => [
'local_cert' => $sslClientCert,
'local_pk' => $sslClientKey,
'SNI_enabled' => true,
'SNI_server_name' => 'THE_URL_I_AM_CALLING'
]
];
$options= [
"soap_version" => SOAP_1_2,
"features" => SOAP_SINGLE_ELEMENT_ARRAYS,
"stream_context" => stream_context_create($contextOptions),
'proxy_host' => $proxy,
'proxy_port' => $port
];
$client = new SoapClient($wsdlUrl, $options);
try {
// execute the search
$searchResults = $client->searchDocuments([
"text" => "myText",
"hint" => "document"
]);
}
catch (Exception $e) {
echo $e->getMessage();
}
the error I get under PHP 7 is
PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host
if I make the call using CURL it works.
I would rather use clientSoap to make my life easier.
I found the solution. Posting it here so no other soul on earth needs to go through this ordeal.
According to the documentation
http://php.net/manual/en/context.ssl.php#context.ssl.sni-server-name
SNI_server_name (string):
If set, then this value will be used as server name for server name indication. If this value is not set, then the server name is guessed based on the hostname used when opening the stream.
Note: This option is deprecated, in favour of peer_name, as of PHP
5.6.0.
After changing:
'SNI_server_name' => 'THE_URL_I_AM_CALLING'
with
'peer_name' => 'THE_URL_I_AM_CALLING'
It works.

Different redis databases for cache and sessions in Laravel 4.2

I am trying to move away from file cache and use redis instead. I can get it working using the same redis database for cache and sessions but this means I cannot clear the application cache without losing all sessions so I am wanting to run the two on different databases on the same server. My configs are as follows:
database.php
'redis' => array(
'cluster' => false,
'default' => array('host' => 'redisserverip', 'port' => 6379, 'database' => 0),
'session' => array('host' => 'redisserverip', 'port' => 6379, 'database' => 1),
),
cache.php
'driver' => 'redis',
'connection' => null,
session.php
'driver' => 'redis',
'connection' => 'session',
This is not working as both the application cache and sessions are being saved into the 1st database when it should be shared accross the 0th and 1st database. Is this a bug in Laravel or a problem with my config?
I dont think its a bug, but the options for making a connection to a Redis server is never being introduced as I can see in Redis Class for Laravel 4.2
protected function createSingleClients(array $servers)
{
$clients = array();
foreach ($servers as $key => $server)
{
$clients[$key] = new Client($server);
}
return $clients;
}
While if you compare it with the Redis Class for Laravel 5 , the options for each server is passed so the feature is supported.
protected function createSingleClients(array $servers)
{
$clients = array();
$options = $this->getClientOptions($servers);
foreach ($servers as $key => $server)
{
$clients[$key] = new Client($server, $options);
}
return $clients;
}
I am taking into consideration, that in your example you are looking for the No cluster option.
The connection parameter has nothing to do with redis, as stated on the config file cache.php
When using the "database" cache driver you may specify the
connection that should be used to store the cached items. When this
option is null the default database connection will be utilized for
cache.

Using SoapClient in php in mule

I am using the following php script in mule. When i am running this php file individually(through wamp) i am able to get the required output.
<?php
$client1=new SoapClient('example/v2_soap?wsdl', array('trace' => 1, 'connection_timeout' => 120));
$username = '******';
$password = '******';
//retreive session id from login
$session = $client1->login(
array(
'username' => $username,
'apiKey' => $password,
)
);
$result= $client1->catalogProductInfo(
array(
'sessionId' => $session->result,
'productId' => 1,
)
);
print_r($result);
return $result;
?>
But i want to run the following script through mule. So when i am running it through mule i am getting the following error.
Root Exception stack trace:
com.caucho.quercus.QuercusErrorException: eval::5: Fatal Error: 'SoapClient' is an unknown class name.
at com.caucho.quercus.env.Env.error(Env.java:4480)
at com.caucho.quercus.env.Env.error(Env.java:4399)
at com.caucho.quercus.env.Env.createErrorException(Env.java:4130)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
It says SoapClient is an unknown class. What is the problem here?
Do i have to include some SoapClient here? If so where can i find it. Please help!!
I'm not sure if mule supports php extensions, but that's what it seems by the error. You could try downloading nusoap into your project,
which doesn't require any php extension. The syntaxis is a little bit different though, but shouldn't be harder to adapt your code.
For what it's worth, this is a simple example of a soap request using nusoap (taken from here http://www.richardkmiller.com/files/msnsearch_nusoap.html):
require_once('nusoap/lib/nusoap.php');
$request = array('Request' => array(
'AppID' => 'MSN_SEARCH_API_KEY',
'Query' => 'Seinfeld',
'CultureInfo' => 'en-US',
'SafeSearch' => 'Strict',
'Flags' => '',
'Location' => '',
'Requests' => array(
'SourceRequest' => array(
'Source' => 'Web',
'Offset' => 0,
'Count' => 50,
'ResultFields' => 'All'))));
$soapClient = new soapclient("http://soap.search.msn.com/webservices.asmx?wsdl", false);
$result = $soapClient->call("Search", $request);
print_r($result);
I hope it helps.
I understand there seems to be a problem with running the soap client inside quercus (rather than Mule).
However instead of focusing on it I would suggest to take a look to the CXF client and the Web services consumer. You are running inside of Mule a powerful opensource ESB, there is no need to write a php script to consume a service, you have all that functinality already present.

How do I turn on the PHP error reporting in Zend Framework 2?

Everytime I receive an error in Zend Framework 2, I get just 500 Internal Server Error displayed and have to search through the Zend Server error log.
I've tried putting this to my config/autoload/local.php file but it doesn't work:
return array(
'phpSettings' => array(
'display_startup_errors' => true,
'display_errors' => true,
),
);
There is no native support for that in zf2 (afaik). You'd either have to set them in php.ini itself, or set them in index.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
If you really want to be able to supply them as config settings, you could keep what you have and do that in a module bootstrap, get them from config, and call ini_set() on each key value pair
public function onBootstrap(EventInterface $e) {
$app = $e->getApplication();
$sm = $app->getServiceManager();
$config = $sm->get('Config');
$phpSettings = isset($config['phpSettings']) ? $config['phpSettings'] : array();
if(!empty($phpSettings)) {
foreach($phpSettings as $key => $value) {
ini_set($key, $value);
}
}
}
Edit: as #akond rightly points out in the comments, you could just add the ini_set lines to local.php which is a better solution.
To easilly configure phpSettings on your ZF2 app, you should consider using DluPhpSettings.
With this module, you can configure your settings for each environment you have:
/* Local application configuration in /config/autoload/phpsettings.local.php */
<?php
return array(
'phpSettings' => array(
'display_startup_errors' => false,
'display_errors' => false,
'max_execution_time' => 60,
'date.timezone' => 'Europe/Prague',
'mbstring.internal_encoding' => 'UTF-8',
),
);
Look this blog post for more info too!

Get a list of bugzilla bugs in PHP

Is it possible to get a list of all new bugs from a bugzilla installation via PHP?
I can see that there is the xmlrpc.cgi file but I can't find any examples of how to use it
Any help appreciated
Thanks!
Example how to do it with Zend_Http_Client. You can do it with raw PHP as well. http://petehowe.co.uk/2010/02/23/example-of-calling-the-bugzilla-api-using-php-zend-framework/
I actually figured out that I can get raw XML using...
/buglist.cgi?ctype=atom&bug_status=NEW
Is this what you're looking for, XMLRPC Bugzilla
Example XMLRPC Call:
<?php
// Add the Zend Library, make sure this is installed: sudo apt-get install libzend-framework-php
ini_set("include_path", "/usr/share/php/libzend-framework-php");
// Add the AutoLoader, Calls any Library that's needed
require_once('Zend/Loader/Autoloader.php');
Zend_Loader_Autoloader::getInstance();
// New client that calls your Bugzilla XMLRPC server
$server = new Zend_XmlRpc_Client('http://bugzilla.yourdomain.com/xmlrpc.cgi');
$client = $server->getProxy();
// Create the Multi-Call array request
$request = array(
array(
'methodName' => 'system.listMethods',
'params' => array()
));
/*
// Example: Multi call array format
$request = array(
array(
'methodName' => 'system.listMethods',
'params' => array()
),
array(
'methodName' => 'your_service.your_function',
'params' => array('parm')
));
*/
// $response is an array()
$response = $client->system->multicall($request);
// Print the array
echo print_r($response,true);
?>

Categories