When using the following connection script:
<?php
ini_set('default_socket_timeout', 120);
$soap_connection_info = array(
'soap_uri' => 'urn:AC',
'soap_host' => '127.0.0.1',
'soap_port' => '7878',
'account_name' => 'acore',
'account_password' => 'password'
);
function RemoteCommandWithSOAP($username, $password, $COMMAND)
{
global $soap_connection_info;
$result = '';
try {
$conn = new SoapClient(NULL, array(
'location' => 'http://' . $soap_connection_info['soap_host'] . ':' . $soap_connection_info['soap_port'] . '/',
'uri' => $soap_connection_info['soap_uri'],
'style' => SOAP_RPC,
'login' => $username,
'password' => $password,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE,
));
$result = $conn->executeCommand(new SoapParam($COMMAND, 'command'));
unset($conn);
} catch (Exception $e) {
$result = "\nHave error on soap!\n" . $e . "\n";
if (strpos($e, 'There is no such command') !== false) {
$result = 'There is no such command!';
}
}
return $result;
}
echo RemoteCommandWithSOAP($soap_connection_info['account_name'], $soap_connection_info['account_password'], ".server info");
?>
With the world server running and listening to port 7878, I get:
local-iMac $ php test.php
Have error on soap!
SoapFault exception: [HTTP] Error Fetching http headers in /Users/dan/dev/test.php:26
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://127.0.0....', 'urn:AC#executeC...', 1, false)
#1 /Users/dan/dev/test.php(26): SoapClient->__call('executeCommand', Array)
#2 /Users/dan/dev/test.php(39): RemoteCommandWithSOAP('acore', 'password', '.server info')
#3 {main}
I know error fetching headers points to a possible timeout when waiting for a response but this error comes up instantly as if there was no wait. However I added in the ini_set('default_socket_timeout', 120); in my script just to be sure.
My worldserver.conf:
# - the DB hostname will be the name of the database docker container
LoginDatabaseInfo = "ac-database;3306;root;password;acore_auth"
WorldDatabaseInfo = "ac-database;3306;root;password;acore_world"
CharacterDatabaseInfo = "ac-database;3306;root;password;acore_characters"
# Add more configuration overwrites by copying settings from worldserver.conf.dist
LogLevel = 5
Appender.File=2,5,7,debug.log,w
Logger.network.soap=5,File
Logger.server.worldserver=5,File
# Disable idle connections automatic kick since it doesn't work well on macOS + Docker
CloseIdleConnections = 0
Updates.EnableDatabases = 1
Death.SicknessLevel = -10
SOAP.Enabled = 1
SOAP.IP = "127.0.0.1"
SOAP.Port = 7878
And my docker-compose is unchanged:
https://github.com/azerothcore/azerothcore-wotlk/blob/master/docker-compose.yml
Interestingly if I down the world container I will get a different response as if it was connecting when it was up.
local-iMac $ php test.php
Have error on soap!
SoapFault exception: [HTTP] Could not connect to host in /Users/dan/dev/test.php:26
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://127.0.0....', 'urn:AC#executeC...', 1, false)
#1 /Users/dan/dev/test.php(26): SoapClient->__call('executeCommand', Array)
#2 /Users/dan/dev/test.php(39): RemoteCommandWithSOAP('acore', 'password', '.server info')
#3 {main}
Also I enabled worldserver logs to see what was going on in SOAP:
2021-09-23_20:41:17 INFO [server.worldserver] > Using configuration file /azerothcore/env/dist/etc/worldserver.conf
2021-09-23_20:41:17 INFO [server.worldserver] > Using SSL version: OpenSSL 1.1.1f 31 Mar 2020 (library: OpenSSL 1.1.1f 31 Mar 2020)
2021-09-23_20:41:17 INFO [server.worldserver] > Using Boost version: 1.71.0
2021-09-23_20:41:17 INFO [server.worldserver]
2021-09-23_20:41:17 INFO [server.worldserver] Process priority class set to -15
2021-09-23_20:41:31 INFO [network.soap] ACSoap: bound to http://127.0.0.1:7878
Also I know container is correctly listening to the port:
f166a28ffdf5 acore/ac-wotlk-worldserver-local:master "./acore.sh run-worl…" 3 weeks ago Up 48 minutes 0.0.0.0:7878->7878/tcp, :::7878->7878/tcp, 0.0.0.0:8085->8085/tcp, :::8085->8085/tcp azerothcore-wotlk_ac-worldserver_1
Some stats on my local:
MacOS Mojave 10.14.6
local-iMac $ docker -v
Docker version 20.10.7, build f0df350
local-iMac $ php -v
PHP 8.0.10 (cli) (built: Aug 26 2021 15:37:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies
Docker acts like a DHCP server and assigns IP's to the containers. You need to check for what the 'local' IP is and that means 'local' to docker.
docker inspect <containerID> | grep IPAddress
That is the ip you need to bind to in your config.
SOAP.Enabled = 1
SOAP.IP = "172.19.0.3"
SOAP.Port = 7878
Related
I have a a logstash tcp server running which accepts a tcp socket connection, I can write to that connection on the php shell.
If I use the same code in a file I get the following lines in logstash debug console and nothing goes into my elasticsearch instance
[DEBUG] 2020-07-15 10:31:40.987 [nioEventLoopGroup-2-3] jsonlines - config LogStash::Codecs::JSONLines/#charset = "UTF-8"
[DEBUG] 2020-07-15 10:31:40.987 [nioEventLoopGroup-2-3] jsonlines - config LogStash::Codecs::JSONLines/#id = "json_lines_dbda8bcd-69ed-4356-81af-381355f76e2f"
[DEBUG] 2020-07-15 10:31:40.987 [nioEventLoopGroup-2-3] jsonlines - config LogStash::Codecs::JSONLines/#enable_metric = true
[DEBUG] 2020-07-15 10:31:40.987 [nioEventLoopGroup-2-3] jsonlines - config LogStash::Codecs::JSONLines/#delimiter = "\n"
Logstash config
input {
tcp {
port => 5080
codec => "json"
id => "PHP_TCP_LOGS"
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "%{[xx]}"
}
}
PHP File
$socket = stream_socket_client('tcp://localhost:5080', $errorNumber, $error, 30);
$a = ["foo"=>"barr"];
fwrite($socket, json_encode($a) . "\n");
echo $error;
I am using workerman PHP library to create WebSocket server.
require dirname(__DIR__) . '/vendor/autoload.php';
use Workerman\Worker;
// Create a Websocket server
$ws_worker = new Worker("websocket://0.0.0.0:8047");
// 4 processes
$ws_worker->count = 4;
// Emitted when new connection come
$ws_worker->onConnect = function($connection)
{
echo "New connection\n";
};
// Emitted when data received
$ws_worker->onMessage = function($connection, $data)
{
var_dump($data);
// Send hello $data
$connection->send('hello ' . $data);
};
// Emitted when connection closed
$ws_worker->onClose = function($connection)
{
echo "Connection closed\n";
};
// Run worker
Worker::runAll();
everything works fine. So I use this class to send message web socket server:
// https://github.com/Textalk/websocket-php
$client = new Client('ws://127.0.0.1:8047/');
$client->send('test !');
Sometimes output this error:
// Validate response.
if (!preg_match('#Sec-WebSocket-Accept:\s(.*)$#mUi', $response, $matches)) {
$address = $scheme . '://' . $host . $path_with_query;
throw new ConnectionException(
"Connection to '{$address}' failed: Server sent invalid upgrade response:\n"
. $response
);
}
If restart server it works again ... but every time after send connection is closes. I can't understand why connection closes.
PHP 7.2.0 (cli) (built: Nov 28 2017 23:48:49) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
I got a Warning from my code
Warning: stream_get_contents(): Failure 'would block' (-9) in /var/www/html/public_html/site.php on line 51
It is thrown only at this command:
service apache2 reload
My code is:
public function exec( $cmd, &$output = '' ) {
$connection = ssh2_connect( '*********', 22 );
ssh2_auth_password( $connection, '********', '******+*' );
$stream = ssh2_exec( $connection, $cmd );
$errorStream = ssh2_fetch_stream( $stream, SSH2_STREAM_STDERR );
stream_set_blocking( $errorStream, TRUE );
stream_set_blocking( $stream, TRUE );
var_dump( $cmd );
echo '<br>';
$output = stream_get_contents( $stream );
$error = stream_get_contents( $errorStream );
if ( strlen( $error ) > 0 ) {
var_dump( $error );
}
fclose( $errorStream );
fclose( $stream );
}
The code is starting at line 39, the warning is on the line with the
$output = stream_get_contents( $stream );
Any solution against the warning ?
EDIT
The function is in a class that is a part of a webinterface to manage the vhosts
Some Informations about the Server:
Apache
root#development:/# apache2 -v
Server version: Apache/2.4.10 (Debian)
Server built: Aug 28 2015 16:28:08
PHP
root#development:/# php -v
PHP 5.6.13-0+deb8u1 (cli) (built: Sep 7 2015 13:38:37)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
OS
root#development:/# uname -a
Linux development 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04) x86_64 GNU/Linux
root#development:/# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.2 (jessie)
Release: 8.2
Codename: jessie
I have looked through almost all existing threads, but I still can't find the problem, so I decided post a new one.
I have code that is running on my live server and the email function is working perfectly fine. It was setup by a contractor and he left no documentation on how to setup CakePHP.
I need to setup my staging server to work exactly the same as the live server. I think I have everything working, except for the email functions. Since I am running exactly the same code on both servers, I am positive that I have missed installing something or setting up configuration on my staging server.
So, what is the framework/module/library needed for CakeEmail? What is the configuration needed for it?
I am running at CakePHP 2.3.4
Here's my code snippet:
App::uses('CakeEmail', 'Network/Email');
$emailTest = new CakeEmail('default');
$emailTest->to('MyEmail#gmail.com');
$emailTest->from(array('me#example.com' => 'My Site'));
$emailTest->subject('About');
try {
$emailTest->send('Hey');
}
catch (SocketException $e) {
echo("Exception: " . $e->getMessage() . "\r\n");
echo("File: " . $e->getFile() . "\r\n");
echo("Line: " . $e->getLine() . "\r\n");
echo("Trace: " . $e->getTraceAsString() . "\r\n");
}
In email.php:
public $default = array(
'transport' => 'Mail',
'from' => 'notification#MySite.com',
// 'charset' => 'utf-8',
// 'headerCharset' => 'utf-8',
);
And I am getting this stack trace:
Exception: Could not send email.
File: /var/www/MySite/lib/Cake/Network/Email/MailTransport.php
Line: 70
Trace: 0 /var/www/MySite/lib/Cake/Network/Email/MailTransport.php(47): MailTransport->_mail('staging#gmail.c...', 'hsbsv vdbeh lik...', 'hsbsv vdbeh lik...', 'From: MySite...', NULL)
1 /var/www/MySite/lib/Cake/Network/Email/CakeEmail.php(1071): MailTransport->send(Object(CakeEmail))
2 /var/www/MySite/app/Model/Notification.php(238): CakeEmail->send('hsbsv vdbeh lik...')
3 [internal function]: Notification->afterSave(true, Array)
4 /var/www/MySite/lib/Cake/Event/CakeEventManager.php(246): call_user_func_array(Array, Array)
5 /var/www/MySite/lib/Cake/Model/Model.php(1772): CakeEventManager->dispatch(Object(CakeEvent))
6 /var/www/MySite/app/Controller/CommentsController.php(160): Model->save(Array)
7 [internal function]: CommentsController->add()
8 /var/www/MySite/lib/Cake/Controller/Controller.php(486): ReflectionMethod->invokeArgs(Object(CommentsController), Array)
9 /var/www/MySite/lib/Cake/Routing/Dispatcher.php(187): Controller->invokeAction(Object(CakeRequest))
10 /var/www/MySite/lib/Cake/Routing/Dispatcher.php(162): Dispatcher->_invoke(Object(CommentsController), Object(CakeRequest), Object(CakeResponse))
11 /var/www/MySite/app/webroot/index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
12 {main}
I started getting these warnings just recently, im not sure why, nor do i know how to fix it. What confuses me more, it was working before, i started working on another class and now i starting getting this error...
im using linux fedora & apache for the webserver.
Warning: simplexml_load_file()
[function.simplexml-load-file]:
php_network_getaddresses: getaddrinfo
failed: Name or service not known in
GetImagesFlickr.php
on line 17
Warning:
simplexml_load_file(http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=9eb9f5e5fb72d6d2fed06cf4e64ba9bb&media=photos&per_page=50&text=fgdc)
[function.simplexml-load-file]: failed
to open stream:
php_network_getaddresses: getaddrinfo
failed: Name or service not known in
GetImagesFlickr.php
on line 17
Warning: simplexml_load_file()
[function.simplexml-load-file]: I/O
warning : failed to load external
entity
"http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=9eb9f5e5fb72d6d2fed06cf4e64ba9bb&media=photos&per_page=50&text=fgdc"
in
/var/www/html/yahoo/GetImagesFlickr.php
on line 17
<?php
class GetImagesFlickr
{
const API_KEY = "***"; // Flickr api key
const MAX_RESULTS_RETURNED = 50; // Max results returned in search
private $url; // Flickr webservice url
public function __construct ()
{
$this->url = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=".self::API_KEY."&media=photos&per_page=".self::MAX_RESULTS_RETURNED;
}
public function getImages ($search_term)
{
// Perform search and store xml data
$xml_data = simplexml_load_file("{$this->url}&text={$search_term}");
$search_results = array();
// Go through xml data and store to array
foreach ($xml_data->photos->photo as $current_photo)
{
$id = $current_photo['id'];
$title = $current_photo['title'];
$farm = $current_photo['farm'];
$secret = $current_photo['secret'];
$server = $current_photo['server'];
$url = "http://farm{$farm}.static.flickr.com/{$server}/{$id}_{$secret}.jpg";
$complete_photo = array (
'id' => $id,
'title' => $title,
'farm' => $farm,
'secret' => $secret,
'server' => $server,
'url' => $url
);
$search_results[] = $complete_photo;
}
return $search_results;
}
}
?>
You have a network/DNS problem, not a PHP problem. Seems your machine cannot resolve the IP of api.flickr.com.
"su" to your web server user and try to resolve the name there, i.e.
$ sudo bash
# get root
$ su - apache
# we're the apache user now
$ ping api.flickr.com