Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fedora / PHP problem #8

Open
philiprhoades opened this issue Aug 4, 2017 · 11 comments
Open

Fedora / PHP problem #8

philiprhoades opened this issue Aug 4, 2017 · 11 comments

Comments

@philiprhoades
Copy link

People,

I installed this on my Fedora 25 x86_64 workstation and immediately got this error:

{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null}

I realised I didn't have php installed but I use nginx instead of Apache so I had to install php-fpm instead of php but I still get that error . . any suggestions about getting this working besides uninstalling nginx, installing httpd and php ?

Thanks,
Phil.

@gidgreen
Copy link
Contributor

gidgreen commented Aug 5, 2017

This looks like an error from the MultiChain API, so that means PHP is already working to some extent (since it's PHP code which calls that API). Please uncomment the two lines (remove the \\) in functions.php that contain print_r and post the extra output you see here. That will show us exactly what request was sent to the MultiChain API from PHP.

@africanswazi
Copy link

Hi there

I also get the {"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null} error.

I am using Apache, PHP 7 on Ubuntu 16.04

Any help would be appreciated

@gidgreen
Copy link
Contributor

@africanswazi If you could follow the request above, that would help us understand and hopefully solve the problem.

@africanswazi
Copy link

Than you

I did uncomment the two lines in functions.php

Below is the code:
`<?php

function read_config()
{
	$config=array();
	
	$contents=file_get_contents('config.txt');
	$lines=explode("\n", $contents);
	
	foreach ($lines as $line) {
		$content=explode('#', $line);
		$fields=explode('=', trim($content[0]));
		if (count($fields)==2) {
			if (is_numeric(strpos($fields[0], '.'))) {
				$parts=explode('.', $fields[0]);
				$config[$parts[0]][$parts[1]]=$fields[1];
			} else {
				$config[$fields[0]]=$fields[1];
			}
		}
	}
	
	return $config;
}

function json_rpc_send($host, $port, $user, $password, $method, $params=array())
{
	$url='http://'.$host.':'.$port.'/';
			
	$payload=json_encode(array(
		'id' => time(),
		'method' => $method,
		'params' => $params,
	));
	
	echo '<PRE>'; print_r($payload); echo '</PRE>';
	
	$ch=curl_init($url);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$password);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		'Content-Type: application/json',
		'Content-Length: '.strlen($payload)
	));
	
	$response=curl_exec($ch);
	
	echo '<PRE>'; print_r($response); echo '</PRE>';
	
	$result=json_decode($response, true);
	
	if (!is_array($result)) {
		$info=curl_getinfo($ch);
		$result=array('error' => array(
			'code' => 'HTTP '.$info['http_code'],
			'message' => strip_tags($response).' '.$url
		));
	}
	
	return $result;
}

function set_multichain_chain($chain)
{
	global $multichain_chain;
	
	$multichain_chain=$chain;
}

function multichain($method) // other params read from func_get_args()
{
	global $multichain_chain;
	
	$args=func_get_args();
	
	return json_rpc_send($multichain_chain['rpchost'], $multichain_chain['rpcport'], $multichain_chain['rpcuser'],
		$multichain_chain['rpcpassword'], $method, array_slice($args, 1));
}

function output_rpc_error($error)
{
	echo '<div class="bg-danger" style="padding:1em;">Error: '.html($error['code']).'<br/>'.html($error['message']).'</div>';
}

function output_success_text($success)
{
	echo '<div class="bg-success" style="padding:1em;">'.html($success).'</div>';
}

function no_displayed_error_result(&$result, $response)
{
	if (is_array($response['error'])) {
		$result=null;
		output_rpc_error($response['error']);
		return false;
	
	} else {
		$result=$response['result'];
		return true;
	}
}

function html($string)
{
	return htmlspecialchars($string);
}

function chain_page_url_html($chain, $page=null, $params=array())
{
	$url='./?chain='.$chain;
	
	if (strlen($page))
		$url.='&page='.$page;
		
	foreach ($params as $key => $value)
		$url.='&'.rawurlencode($key).'='.rawurlencode($value);
		
	return html($url);
}

function array_get_column($array, $key) // see array_column() in recent versions of PHP
{
	$result=array();
	
	foreach ($array as $index => $element)
		if (array_key_exists($key, $element))
			$result[$index]=$element[$key];
	
	return $result;
}

function multichain_getinfo()
{
	global $multichain_getinfo;
	
	if (!is_array($multichain_getinfo))
		no_displayed_error_result($multichain_getinfo, multichain('getinfo'));
	
	return $multichain_getinfo;
}

function multichain_labels()
{
	global $multichain_labels;
	
	if (!is_array($multichain_labels)) {
		if (no_displayed_error_result($items, multichain('liststreampublishers', 'root', '*', true, 10000))) {
			$multichain_labels=array();
			foreach ($items as $item)
				$multichain_labels[$item['publisher']]=pack('H*', $item['last']['data']);
		}
	}
	
	return $multichain_labels;
}

function multichain_max_data_size()
{
	global $multichain_max_data_size;
	
	if (!isset($multichain_max_data_size))
		if (no_displayed_error_result($params, multichain('getblockchainparams')))
			$multichain_max_data_size=min(
				$params['maximum-block-size']-80-320,
				$params['max-std-tx-size']-320,
				$params['max-std-op-return-size']
			);
	
	return $multichain_max_data_size;
}	

function format_address_html($address, $local, $labels, $link=null)
{
	$label=@$labels[$address];
	
	if (strlen($link)) {
		$prefix='<a href="'.html($link).'">';
		$suffix='</a>';
	} else {
		$prefix='';
		$suffix='';
	}
	
	if (isset($label))
		$string=html($label).' ('.$prefix.html($address).$suffix.($local ? ', local' : '').')';
	else
		$string=$prefix.html($address).$suffix.($local ? ' (local)' : '');
		
	return $string;
}

function string_to_txout_bin($string)
{
	return ltrim($string, "\x00"); // ensures that first byte 0x00 means it's a file
}

function file_to_txout_bin($filename, $mimetype, $content)
{
	return "\x00".$filename."\x00".$mimetype."\x00".$content;
}

function txout_bin_to_file($data)
{
	$parts=explode("\x00", $data, 4);
	
	if ( (count($parts)!=4) || ($parts[0]!='') )
		return null;
	
	return array(
		'filename' => $parts[1],
		'mimetype' => $parts[2],
		'content' => $parts[3],
	);
}

function fileref_to_string($vout, $filename, $mimetype, $filesize)
{
	return "\x00".$vout."\x00".$filename."\x00".$mimetype."\x00".$filesize;
}

function string_to_fileref($string)
{
	$parts=explode("\x00", $string);
	
	if ( (count($parts)!=5) || ($parts[0]!='') )
		return null;
		
	return array(
		'vout' => $parts[1],
		'filename' => $parts[2],
		'mimetype' => $parts[3],
		'filesize' => $parts[4],
	);
}`

when I dug deeper in the Google Chrome console I saw this additional error:

failed to load resource: the server responded with a status of 500 (Internal Server Error)

Thanks in advance

@gidgreen
Copy link
Contributor

So that's the $response you are seeing. But I don't see why you don't see the $payload that should also be output in the browser. Is any error showing in your web server's error log?

@africanswazi
Copy link

I don't see anything in the error log:

[Tue Nov 21 08:13:50.606613 2017] [mpm_prefork:notice] [pid 2309] AH00163: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations [Tue Nov 21 08:13:50.607841 2017] [core:notice] [pid 2309] AH00094: Command line: '/usr/sbin/apache2'

Above is today's log so nothing weird and out of the ordinary.

I wonder if this is not anything to do with Ubuntu 16.04 only using PHP 7 by default. I am going to run Ubuntu 14 in a VM and see if it works with PHP 5

Cheers

@gidgreen
Copy link
Contributor

Yes, it could be a PHP 5 vs 7 issue.

@africanswazi
Copy link

I get the same error with Ubuntu 14.04, PHP5 and Apache

{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null}

I have also removed the \ in functions.php that contain print_r and there is no extra output

It must be something silly that I am missing.

@gidgreen
Copy link
Contributor

gidgreen commented Nov 22, 2017

OK, we're still trying to understand how this json_rpc_send() function is operating so that nothing is output for the $payload variable earlier on.

Can you please add this at the very start of the function:

$args=func_get_args(); echo '<PRE>['; print_r($args); echo ']</PRE>';

Then let us know what is shown in your web browser.

@africanswazi
Copy link

Thank you for the response

I did the above but no change. Still the same error with nothing else. I am starting to wonder if I am editing the wrong file in the wrong folder maybe?

I downloaded and extracted the files to my downloads folder in Ubuntu. Is there any other location where I should look maybe?

Best,

@gidgreen
Copy link
Contributor

Yes, the files will be in your web server's directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants