Elasticsearch-PHP application not working - php

I have an Elasticsearch-PHP application and it works locally. However, when I put it on an RHEL 6 server that only supports PHP 5.3, it does not work. When I go to the console, I get GET http://xx.x.xxx.xxx:xxxx/init.php 500 (Internal Server Error). The problem I think might be from a connection issue in the init.php. Here's the code inside init.php:
<?php
require_once 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
/*Build connection*/
$hosts = [
'xx.x.xxx.xxx', // Port
];
$es = ClientBuilder::create() // Instantiate a new ClientBuilder
->setHosts($hosts) // Set the hosts
->build(); // Build the client object
?>
This works perfect locally. I don't know why it doesn't work when I transfer it to the server.

In PHP 5.3.10 the short array syntax was not available, you can simply fix your code by using array() instead:
$hosts = array(
'xx.x.xxx.xxx', // Port
);

Related

Where does Zend framework keep the default certificate store?

I have two environments, a development one and production one which mirrors the development environment.
On the development environment, I'm trying to connect to a ssl server using the zend framework and I got the following meaningless error message;
Unable to Connect to ssl://test.server.com:443. Error #0:
Using tcpdump, I found the error was due to an Unknown CA.
Here is my code:
require_once 'Zend/Http/Client.php';
$uri = 'https://test.server.com';
$client = new Zend_Http_Client($uri);
$client->setHeaders(Zend_Http_Client::CONTENT_TYPE, 'application/json');
$response = $client->setRawData($json)->setEncType('application/json')->request('PUT');
I have not specified an sslcapath, however my production system works fine without it. When I -do- set the sslcapath,
$client = new Zend_Http_Client($uri, array(
'sslcapath' => '/etc/ssl/certs'
));
I still get the error.
So I think that Zend is using a certificate store somewhere (or I am setting the sslcapath incorrectly), and I would like to check if the CA is in the certificate store on the development environment.
My CA is in /etc/ssl/certs on both systems.
Is there anything else which would explain why it works on the production system, but not the development, despite being the same?
Based on your code given, you have not define the Zend_Http_Client_Adapter. Then the configuration will be different depends on which adapter do you choose.
https://framework.zend.com/manual/1.11/en/zend.http.client.adapters.html
Example using socket:
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Socket',
'sslcert' => '/etc/ssl/certs'
);
// Instantiate a client object
$client = new Zend_Http_Client($uri, $config);
$client->setHeaders(Zend_Http_Client::CONTENT_TYPE, 'application/json');
$response = $client->setRawData($json)->setEncType('application/json')->request('PUT');
You can use another adapter based on your need or which adapter you like.

Websocket: Cannot establish a connection with basic websocket server

I've tried very basic websocket tutorial using ratchet php, exactly as shown in http://socketo.me/docs/hello-world
Code for websocket server:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require 'vendor/autoload.php';
require 'chat.php';
use Ratchet\Server\IoServer;
use HHWS\Chat;
$server = IoServer::factory(
new Chat(),
8080
);
$server->run();
To run the server I did:
$ php ws-server.php
And to test the connection with the server I did:
telnet 127.0.0.1 8080
This worked perfectly fine when tested LOCALLY. Users can chat using multiple telnet terminals.
I then uploaded the code to live server. And the tried running the server.
Then tried to connect to this server using telnet just like before, it couldn't connect.
All it shows is "Trying.." message and then " Unable to connect to remote host: Connection timed out".
I don't know why this is happening, and what the problem is. The code is exactly the same. And this is very basic hello world example I'm doing. Can anyone help me on this.
Do using "Websockets" have any other requirements on the live server to work.
Update:
Actually, the live server is Amazon EC2; does this require setting up additional things for websocket to work?

Apache Solr extension in PHP - Solr HTTP Error : 'Couldn't connect to server'

I am trying to install the Apache Solr extension for PHP on my Windows box.
A quick look at phpinfo(); shows that the extension has been loaded.
Apart from changing SOLR_SERVER_HOSTNAME to match my own Virtual Host, everything as the same as on the PHP Solr Example page.
When I run solr_test.php, I get the following error:
Warning: SolrClient::addDocument(): Solr HTTP Error : 'Couldn't connect to server'
The PHP Solr page says: The Solr extension allows you to communicate effectively with the Apache Solr server in PHP 5 so I am assuming that I do not need to run anything else to make this extension work. Is that correct?
Do I need to set up an additional Virtual Host for Solr, e.g solr.mysite?
Here is my bootstrap.php file:
<?php
/* Domain name of the Solr server */
define('SOLR_SERVER_HOSTNAME', 'test.mysite');
/* Whether or not to run in secure mode */
define('SOLR_SECURE', true);
/* HTTP Port to connection */
define('SOLR_SERVER_PORT', ((SOLR_SECURE) ? 8443 : 8983));
/* HTTP Basic Authentication Username */
define('SOLR_SERVER_USERNAME', 'admin');
/* HTTP Basic Authentication password */
define('SOLR_SERVER_PASSWORD', 'changeit');
/* HTTP connection timeout */
/* This is maximum time in seconds allowed for the http data transfer operation. Default value is 30 seconds */
define('SOLR_SERVER_TIMEOUT', 10);
?>
Here is my solr_test.php page:
<?php
include "bootstrap.php";
$options = array
(
'hostname' => SOLR_SERVER_HOSTNAME,
'login' => SOLR_SERVER_USERNAME,
'password' => SOLR_SERVER_PASSWORD,
'port' => SOLR_SERVER_PORT,
);
$client = new SolrClient($options);
$doc = new SolrInputDocument();
$doc->addField('id', 334455);
$doc->addField('cat', 'Software');
$doc->addField('cat', 'Lucene');
$updateResponse = $client->addDocument($doc);
print_r($updateResponse->getResponse());
?>
I'm a bit concerned about this line here:
define('SOLR_SERVER_PORT', ((SOLR_SECURE) ? 8443 : 8983));
As far as I'm aware this type of logic will only be supported in PHP 5.6. That said I feel like your PHP script should error out. See if something like
define('SOLR_SERVER_PORT', 8983);
remedies the situation.
Make sure Solr server details are correct. I get this error only when I pass something wrong like SOLR_SERVER_PORT etc.
Please try following terminal commands may helps, to disable temporary firewall settings:
sestatus
setenforce Permissive

php soap client returns 404, when calling WSDL methods from HTTPS environment

I am running a php soap client example under https environment of my Zend Server.
I am able to list the methods in the WSDL. But when i make a call to one of those methods, i receive a 404 HTTP not found error. I also tried saving the WSDL to my local folder.
Interestingly, the same example was running successfully from the CLI (like: C:/> php abc.php). Not sure why it is failing in the browser (like: https://example.com:10022/abc.php).
This is my code:
<?php
ini_set("soap.wsdl_cache_enabled", "0");
try {
$client = new SoapClient('country.wsdl');
//$client = new SoapClient('http://www.webservicex.net/country.asmx?WSDL');
//$functions = $client->__getFunctions (); var_dump ($functions); // works
$params = array('CountryName'=> 'Australia');
$result = $client->GetISOCountryCodeByCountyName($params);
echo $result->GetISOCountryCodeByCountyNameResult;
}
catch(SoapFault $fault) {
echo $fault->getMessage();
}
?>
Note:
I have openssl enabled.
My https url is configured as a Zend server Virtual Host, running on port 10022.
My https url is not reachable from outside world (does this make any difference?)

SOAP and SSL in PHP

I've got a problem with SOAP and SSL.
When I create a SOAP client with normal wsdl (http), it runs ok. But when I connect with a SSL wsdl (https) it's got problem.
I tried the same code to connect to the https wsdl at my localhost, it's OK. But it doesn't work if that code run under my server.
My server is running Centos, PHP 5.3.8. Can you show me how to config PHP to run SOAP with SSL. Below is my current code:
<?php
// where BKTransactionAPI extends SoapClient...
$bk = new BKTransactionAPI("https://www.baokim.vn/services/transaction_api/init?wsdl");
$info_topup = new TopupToMerchantRequest();
$info_topup->card_id = $service;
$info_topup->pin_field = $pin;
$info_topup->transaction_id = $transaction_id;
$result = new TopupToMerchantResponse();
$result = $bk->DoTopupToMerchant($info_topup);
?>

Categories