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
Related
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
I am writing this in shell;
sudo tail -100 /var/log/apache2/error.log
And, I saw this;
......
[Sun Feb 14 09:42:06.873076 2021] [php7:warn] [pid 1968] [client 82.222.237.83:36955] PHP Warning: ltrim() expects parameter 1 to be string, object given in /var/www/html/wp-includes/formatting.php on line 4314
[Sun Feb 14 09:42:06.873149 2021] [php7:warn] [pid 1968] [client 82.222.237.83:36955] PHP Warning: ltrim() expects parameter 1 to be string, object given in /var/www/html/wp-includes/formatting.php on line 4314
...
I'm going to the relevant code. --> /var/www/html/wp-includes/formatting.php on line 4314
function esc_url( $url, $protocols = null, $_context = 'display' ) {
$original_url = $url;
if ( '' === $url ) {
return $url;
}
$url = str_replace( ' ', '%20', ltrim( $url ) );
$url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%#$\|*\'()\[\]\\x80-\\xff]|i', '', $url );
if ( '' === $url ) {
return $url;
}
if ( 0 !== stripos( $url, 'mailto:' ) ) {
$strip = array( '%0d', '%0a', '%0D', '%0A' );
$url = _deep_replace( $strip, $url );
}
$url = str_replace( ';//', '://', $url );
on line 4314;
$url = str_replace( ' ', '%20', ltrim( $url ) );
I did not understand. My error page is full of this. I could not figure out despite my research. Can you help me?
Note: Ubuntu 20.04, Wordpress
Healthy days,
Best regards.
The function esc_url() is called with a $url that is object rather a string. You can use gettype() or print_r() to confirm. debug_backtrace() might be useful to figure out where you are making those calls from.
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
Moodle REST APIs failing intermittently and returning 500 (Internal Server Error)
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.30-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
<?php
error_reporting(-1); // reports all errors
ini_set("display_errors", "1"); // shows all errors
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details
*
* #package local_lingk
* #copyright (C) 2018 Lingk Inc (http://www.lingk.io)
* #license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once '../config.php';
//require_once '../lib/moodlelib.php';
// require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->libdir.'/moodlelib.php');
require_once 'src/Mandrill.php'; //Not required with Composer
global $DB, $CFG, $SESSION, $USER;
$CFG = new stdClass();
$CFG->dataroot = '/usr/src/moodle/moodledata';
$CFG->cookiename = 'MoodleSession';
$USER = new stdClass();
$USER->id = -10;
$USER->email = 'emailed';
$USER->firstname = 'Do not reply to this email';
$USER->username = 'noreply';
$USER->lastname = '';
$USER->confirmed = 1;
$USER->suspended = 0;
$USER->deleted = 0;
$USER->picture = 0;
$USER->auth = 'manual';
$USER->firstnamephonetic = '';
$USER->lastnamephonetic = '';
$USER->middlename = '';
$USER->alternatename = '';
$USER->imagealt = '';
$USER->maildisplay = 1;
$USER->emailstop = 1;
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Allow-Credentials: true");
header('Content-Type: application/json');
header("HTTP/1.0 200 Successfull operation");
// echo '=============+++++++';exit;
$wsfunction = $_POST['wsfunction'];
// print_r($record);exit;
// $client_id = $_POST['client_id'];
// $client_secret = $POST['client_secret'];
// $device_id = $POST['device_id'];
$response = array();
I tried changing apache config and mysql config but APIs are failing intermittently. It works 2 times and fails on 3rd and sometimes succeeds thrice and fails on fourth attempt. Am I missing any configuration or moodle setting?
i was programming a mail templatingsystem. The user should be able to use markers in there, they will be replaced by the actual data. The problem ist, my function to replace the markers works just fine, but i need to do a recursiv call of that function, that will only run once, and this is what i came up with:
public function replace_placeholders($content, $recipient, $settings, $interface, $recommendation, $format, $recursion = false) {
$content = $this->replace_ph('briefanrede' , $recipient['id'] , $content);
$content = $this->replace_ph('anrede' , $recipient['title'] , $content);
$content = $this->replace_ph('email' , $recipient['email'] , $content);
$content = $this->replace_ph('kundennummer' , $recipient['kdnumber'] , $content);
$content = $this->replace_ph('briefanrede' , $recipient['briefanrede'] , $content);
if($recipient['title'] == $settings['anrede_w'] || $recipient['title'] == $settings['anrede_m']) {
$content = $this->replace_ph('vorname' , $recipient['forename'] , $content);
$content = $this->replace_ph('nachname' , $recipient['surename'] , $content);
} else {
$content = $this->replace_ph('vorname' , "" , $content, true);
$content = $this->replace_ph('nachname' , "" , $content, true);
}
$content = $this->replace_salutation($recipient, $settings, $content);
//Recommendation
if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false) {
if($recommendation['own_page'] == 1) {
$baseurl = $recommendation['location'];
} else {
$baseurl = $recommendation['link'];
}
$pattern = ($format == "html") ? '%s' : '%s';
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);
$content = $this->replace_ph('weiterempfehlung' , (($format == "html") ? sprintf($pattern, $url, $settings['text_weiterempfehlung']): sprinf($pattern, $url)), $content);
}
return $content;
}
The recursiv call in this line
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);
is causing a 500 internal server error. I dont know why, because i think that i limited the recursion to run once. Can you help me out?
Sorry for my bad english i try hard to write clear sentences.
//EDIT:
Apache log:
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
[Wed May 30 15:31:56 2012] [error] [client xx.xxx.xx.xxx] File does not exist: /var/www/web80/html/web80-newsletter/favicon.ico
[Wed May 30 15:31:58 2012] [error] mod_fcgid: process /var/www/php-fcgi/web80.php53/php-fcgi(21975) exit(communication error), get unexpected signal 11
the php errorlog is empty.
It would seem you miss one argument in your recursive call, making the $recursive = false continue being false all the time, which in turn makes your if statement
if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false)
always return true.
Try adding one last variable to your recursive call instead and you should be able to properly execute your script, ie:
$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface,
$recommendation, true, true);
^ added one true
What i think you want to add instead of the first true is $format.
Signal 11 is SIGSEGV, i.e. the process crashed due to a bad memory access (such as dereferencing a NULL pointer or accessing memory it was not supposed to access).
This is nothing a PHP script should be causing, so you should first upgrade to the most recent stable PHP version and if it still happens reduce your script as much as possible (remove everything that can be removed while the crash still happens) and then report it as a PHP bug.