PHP connection Wamp+Solr - php

I am trying to setup and test a connection using php.
Below you will notice I have not defined base, which will be my home directory for the 'require_once'. My question is regarding what needs to be on the line for require once?
<?php
define('base',
require_once( 'C:\Program Files\Solr\solr-7.5.0\server\solr\sqltest' );
$options = array
(
'hostname' => 'localhost',
'login' => 'root',
'password' =>'',
'port' => '8983',
'path' => 'C:\Program Files\Solr\solr-7.5.0\server\solr\sqltest'
);
$client = new SolrClient( $options );
if ( ! $solr->ping() ) {
echo 'Solr service not up dude.';
exit;
}
?>
My local server was setup using Wamp. Many pages I have looked at for help use another service and their request_once is like this:
require_once( 'Apache/Solr/Service.php' );
this leads me to believe mine should point to something in my wamp directory

Turns out I am missing the solr php client
https://github.com/PTCInc/solr-php-client

Related

How to read PHP file which contains array

I have a php file, config.php and it contains following code.
$_config = array(
'db' => array(
'mysolidworks' => array(
'host' => 'localhost',
'username' => 'netvibes',
'password' => 'frakcovsea',
'dbname' => 'sw_mysolidworks',
'driver_options' => array(
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
)
)
)
);
I want to read this file into a variable and then read the variable like an array. Could anyone help?
Simply using PHP the way it's meant to work:
include('config.php');
echo $_config['db']['mysolidworks']['host'];
you can use any of the following
<?php
$file_loc = 'SomeDir/config.php';
require $file_loc; //Throw a fatal if it's not found
require_once $file_loc; //If this might be called somewhere else in your script, only include it once
include $file_loc; //Include but just show a warning if not found
include_once $file_loc; //Include if not already included and throw warning if not
?>

PHP Solr connection issue

I have PHP-Solr extension version 1.0.3-alpha installed on my server. I'm initializing the connection using:
$options = array(
'hostname' => 'hostname',
'login' => '',
'password' => '',
'port' => '',
'path' => 'solr/core1');
$client = new SolrClient($options);
It returns the following object:
class SolrClient#17 (1) { private $_hashtable_index => int(13444) }
But whenever I try to run a query like:
$qryArray = 'key_id:123456';
$client->deleteByQuery($qryArray);
It throws an exception as follows:
Solr HTTP Error 7: 'Couldn't connect to server
Can anyone help me to find what would causing this issue?
I have tried var_dump($client->getDebug());, but it returns NULL.

phalcon framework webtools not working when creating models, views and controllers

I'm having some problems while trying to get phalcon webtools working.
When using command line devtools I can create controllers and models without problems.
However, things aren't that easy with the webtools.
It correctly shows already created controllers and models:
Controllers (http://i.imgur.com/IRWPaVJ.png)
Models (http://i.imgur.com/rIbvbg9.png)
And I can also edit them (http://i.imgur.com/orJweLl.png).
Apparently, Db connexion is ok, since webtools shows every table in the DB:
Models (http://i.imgur.com/iOkZfyo.png)
Scaffolding (http://i.imgur.com/5ZLRuq5.png)
However, when trying to create a controller from the web interface, I got the next error:
"Please specify a controller directory"
Same when trying to create a Model from a database table :
"Database configuration cannot be loaded from your config file"
Or when trying to generate scaffold :
"Adapter was not found in the config. Please specify a config variable
[database][adapter]"
My app/config/config.php content:
return new \Phalcon\Config(array(
'database' => array(
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'phalcon',
'password' => 'phalcon',
'dbname' => 'phalcon',
'charset' => 'utf8',
),
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
'viewsDir' => __DIR__ . '/../../app/views/',
'pluginsDir' => __DIR__ . '/../../app/plugins/',
'libraryDir' => __DIR__ . '/../../app/library/',
'cacheDir' => __DIR__ . '/../../app/cache/',
'baseUri' => '/phalconTest/',
)
));
My public/webtools.config.php content:
define('PTOOLS_IP', '192.168.248.135');
define('PTOOLSPATH', 'C:/phalcon-devtools');
My public/webtools.php:
use Phalcon\Web\Tools;
require 'webtools.config.php';
require PTOOLSPATH . '/scripts/Phalcon/Web/Tools.php';
Tools::main(PTOOLSPATH, PTOOLS_IP);
Im running Phalcon 1.3.4 - Windows x86 for PHP 5.4.0 (VC9)
It seems like a bug in webtools.
Look at vendor/phalcon/devtools/scripts/Phalcon/Builder/Component.php
there is the _getConfig function.
The quick and dirty solution is prepend ../ to path.
You need to change the first line in app/config/config.php
defined('APP_PATH') || define('APP_PATH', realpath('..'));
To add to some of the answers, the editing of configPath by prepending ../ and also some code changes, has forgotten a a little '/' when modelPath has been rtrimmed.
Also, code will be updated and fixed but as of now, one can probably fix the issues by editing your/path/phalcon-devtools/scripts/Phalcon/Builder/Model.php; find
$modelsDir = rtrim(rtrim($modelsDir, '/'), '\\') . DIRECTORY_SEPARATOR;
if ($this->isAbsolutePath($modelsDir) == false) {
$modelPath = $path . DIRECTORY_SEPARATOR . $modelsDir;
} else {
// $modelPath = $modelsDir;
// replace or ADD TO LINE ABOVE so it looks like BELOW:
$modelPath = DIRECTORY_SEPARATOR . $modelsDir;
}
Then Models will work in webtools along with TKF's answer. Enjoy.
Apply changes in webtools.config.php like here:
<?php
if (!defined('PTOOLS_IP'))
define('PTOOLS_IP', '192.168.');
if (!defined('PTOOLSPATH'))
define('PTOOLSPATH', '/path/to/phalcon/devtools');
return array(
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
),
'database' => array(
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'usr',
'password' => 'pwd',
'dbname' => 'dbname',
)
);
Somewhat related, I had an issue with the webtools url getting longer and longer .. Eventually I could fix this by adding the word webtools in a replacement for the baseUri in config.php .
<?php ### config.php ... somewhat relevant parts ...
return new \Phalcon\Config([
'database' => [ # ... some things ...
],
'application' => [ # ... some more ...
// This allows the baseUri to be understand project paths that are not in the root directory
// of the webpspace. This will break if the public/index.php entry point is moved or
// possibly if the web server rewrite rules are changed. This can also be set to a static path.
'baseUri' => preg_replace(
'/(public([\/\\\\]))?(index)|(webtools).php$/',
'',
$_SERVER["PHP_SELF"]
),
]
]);

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.

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

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;
?>

Categories