Codeigniter's XML-RPC shows no response data - debugging

I'm attempting to connect to an XML RPC server with no luck, I am getting an empty response with no debugging information whatsoever. I've switched on set_debug(), but still nothing.
Can anyone tell me why I am getting no response from the server, no error information and no debug information?
$this->load->library('xmlrpc');
$this->xmlrpc->set_debug(TRUE);
$this->xmlrpc->server('https://myurl.com/xmlrpc', 80);
$this->xmlrpc->method('login');
$request = array('param1', 'param2');
$this->xmlrpc->request($request);
echo 'Error: '. $this->xmlrpc->display_error() . '<br/>';
echo 'Response: '. print_r($this->xmlrpc->display_response(), true) . '<br/>';

Even if you type https:// in server method you are still connecting with server via http, look at 2nd parameter - the port you have set is 80.
Just in case.

I forgot to use:
$this->xmlrpc->send_request()
its best used in a conditional statement like:
if ( ! $this->xmlrpc->send_request())
{
echo $this->xmlrpc->display_error();
}
else
{
echo '<pre>';
print_r($this->xmlrpc->display_response());
echo '</pre>';
}

Related

Binance websocket API sends opcode 8 (connection close) 1 second after successful connect & transfer

I'm having a problem with Binance's websocket API closing the connection almost immediately. The connect and websocket upgrade succeeds, and there's (usually) some of the expected data sent back, but the remote end sends websocket opcode 8 (connection close) less than a second after subscribing. Here's some example debug output; note the time between the initial connect and then reconnect is <= 1 second.
*** Connecting to server: stream.binance.com at 2021-05-25 16:06:48 UTC+0
websocket: connecting to ssl://stream.binance.com:9443 with path /ws/btcusdt#trade
websocket: connected
websocket: sent upgrade request
websocket: successful upgrade
Sending message to server: '{"method":"SUBSCRIBE","params":["btcusdt#trade"],"id":1}'
{"e":"trade","E":1621958809390,"s":"BTCUSDT","t":871186927,"p":"37950.99000000","q":"0.08750200","b":6146242615,"a":6146242639,"T":1621958809389,"m":true,"M":true}
{"e":"trade","E":1621958809390,"s":"BTCUSDT","t":871186928,"p":"37948.01000000","q":"0.27946700","b":6146242632,"a":6146242639,"T":1621958809389,"m":true,"M":true}
errstr=Remote sent opcode 8 (close)
*** Connecting to server: stream.binance.com at 2021-05-25 16:06:49 UTC+0
websocket: connecting to ssl://stream.binance.com:9443 with path /ws/btcusdt#trade
websocket: connected
websocket: sent upgrade request
websocket: successful upgrade
Sending message to server: '{"method":"SUBSCRIBE","params":["btcusdt#trade"],"id":1}'
{"e":"trade","E":1621958810172,"s":"BTCUSDT","t":871186935,"p":"37945.47000000","q":"0.00561300","b":6146242792,"a":6146242898,"T":1621958810171,"m":true,"M":true}
{"e":"trade","E":1621958810172,"s":"BTCUSDT","t":871186936,"p":"37945.43000000","q":"0.01233600","b":6146242721,"a":6146242898,"T":1621958810171,"m":true,"M":true}
{"e":"trade","E":1621958810183,"s":"BTCUSDT","t":871186937,"p":"37945.43000000","q":"0.00140200","b":6146242721,"a":6146242907,"T":1621958810183,"m":true,"M":true}
{"e":"trade","E":1621958810199,"s":"BTCUSDT","t":871186938,"p":"37945.36000000","q":"0.00484000","b":6146242644,"a":6146242914,"T":1621958810199,"m":true,"M":true}
{"e":"trade","E":1621958810203,"s":"BTCUSDT","t":871186939,"p":"37945.36000000","q":"0.08219200","b":6146242644,"a":6146242916,"T":1621958810203,"m":true,"M":true}
{"e":"trade","E":1621958810204,"s":"BTCUSDT","t":871186940,"p":"37945.36000000","q":"0.04644700","b":6146242644,"a":6146242917,"T":1621958810204,"m":true,"M":true}
errstr=Remote sent opcode 8 (close)
I'm using a simple PHP websocket client, slightly modified to output additional debug info: https://github.com/paragi/PHP-websocket-client , however the debug output above should be sufficient to show the subscribe process, and all other relevant parameters.
The same client works fine on another exchange's API.
I temporarily modified the client code to ignore opcode 8, but in that instance Binance enforces the close by closing the TCP socket.
I also tried this on a completely different server (located in another country, different ASN) in case it was my local IP/ASN that was the issue. Same problem.
Any ideas? I am new to websockets, and the Binance API, so perhaps I've done something silly. Thanks for any assistance.
EDIT: Here is minimal code to demonstrate the error. Requires https://github.com/paragi/PHP-websocket-client.git
Note: if there's no data returned, try running it a few times. Results are not consistent.
require_once("PHP-websocket-client/websocket_client.php");
// git clone https://github.com/paragi/PHP-websocket-client.git
$server = "stream.binance.com";
$serverport = 9443;
$streamname = "btcusdt#trade";
$t = array("method" => "SUBSCRIBE", "params" => array("$streamname"), "id" => 1);
$uri = "/ws/$streamname";
$message = json_encode($t) . "\n";
echo "\n*** Connecting to server: $server at " . gmdate("Y-m-d H:i:s") . " UTC+0\n";
$sp = websocket_open($server, $serverport,'',$errstr, 30, true, false, $uri);
if ($sp) {
echo "Sending message to server: '" . trim($message) . "' \n";
websocket_write($sp,$message);
while (1) {
$r = websocket_read($sp,$errstr);
echo "$r\n";
if ($r == "") {
echo "errstr=$errstr\n";
die;
}
}
}
?>

Codeigniter to Generate Text View

I need to generate Text view of data but some links are working fine but some are not showing the results as text.
http://www.ipaddresshost.com/downloads/ch.cidr - CH CIDR is not in Text Format
http://www.ipaddresshost.com/downloads/af.cidr - AF CIDR is in Text Format
My Code is as under:
$cidr_result = $this->webmodel_downloads->singlecountrycidr($country_code2);
//$this->load->helper('text');
//$this->load->helper('file');
//echo "# Generated ". date('Y-m-d')."\n";
$this->output->set_content_type('text/plain', 'UTF-8');
$this->output->set_header("Content-Type: text/plain");
echo "# Generated ". date('Y-m-d').PHP_EOL;
if (!empty($cidr_result)){
foreach($cidr_result as $row){
echo $row['value'].PHP_EOL;
//print_r($row['value'].PHP_EOL);
}
}
Please help me, if I am doing some mistake. Thank you
I do not Know the Technical Reason behind this but instead of using CodeIgniter function for text header, I used PHP Header and It's working Fine;
header ("Content-type: text/plain");

On line email form hangs on php mail() function. What server issue could be causing this?

I have a contact form on my website that has a dead simple php mail() function. I am 99% certain the php is not the issue as I have the exact same function on other sites that works fine.
However, when I try to use the form on one site in particular it seems to hang and not send the email and not redirect to the success page. Would anyone know what could be causing this on the server side?
If anyones interested my php is:
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$company = $_REQUEST['company'] ;
$phone = $_REQUEST['phone'] ;
$message= $_REQUEST['message'] ;
$webmaster_email = "myemail#mysite.com";
$thankyou_page = "http://www.mysite.com/thanks-for-your-inquiry.html";
mail( "$webmaster_email", "Site Form", "From: noreply#mysite.com",
"From: $email \n
Name: $name \n
Phone: $phone\n
Message: $message\n ");
header( "Location: $thankyou_page" );

Lithium: Can we see queries executed as shown in CakePHP

Do you know of any method to show the queries being executed in Lithium as it does in CakePHP.
It may become easier for me to find what is executed.
At the bottom of the page it shows the queries executed.
![The screen shot] http://imgur.com/ffNfQ
After I received the answer, I added the code to my controller:
Volumes::applyFilter('find', function($self, $params, $chain) {
echo '<pre>===== self ======<br>';
var_dump($self);
echo '===== params ======<br>';
var_dump($params);
echo '===== chain ======<br>';
var_dump($chain);
echo '</pre>';
$next = $chain->next($self, $params, $chain);
return $next;
});
It gives me an output as to all var_dump of self and params, but I require the SQL query which gets executed.
Please check the screen shot http://imgur.com/ffNfQ
as #Nils suggested, you can leverage Lithium filters and write a simple queries logger.
I made one here. It logs the read queries to a file on a production environment.
You should be able to customize, and add filters on create, update and delete operations to fit your needs.
If you are looking to an out-of-the-box solution like Cake's debug toolbar, check the li3_perf project: https://github.com/tmaiaroto/li3_perf
You can do this by adding filters to the types of queries you wish to log. You can define them globaly in the bootstrap files our you can define them "localy" in the controllers. The example bellow does not print the query nice, however that is pretty easy to do when you have the data.
The code bellow shows how to get the information, it does not output it in a pretty way.
Connections::get('default')->applyFilter('read', function($self, $params, $chain) {
echo "===========</br>\n";
if (is_object($params['query'])){
var_dump($params['query']->conditions());
}
else{
echo 'Query: '; var_dump($params['query']); echo "</br>\n";
}
$time = microtime(true);
$next = $chain->next($self, $params, $chain);
$time = microtime(true) - $time;
echo "Results: " . count((array)$next) . "</br>\n";
echo "Time: " . $time . "</br>\n";
return $next;
});
Please note that echo it the data directly from the filter will render your page useless as this will be printed before headers. However if you save the data in the filter to an array instead of outputting it you can use it later in your views. And you can for instance make a template to add this information to the page.
Edit: updated code
Edit2: added a way to always get the exact SQL that is executed. To get the
Connections::get('default')->applyFilter('_execute', function($self, $params, $chain) {
echo "SQL: " . $params['sql'] . "</br>\n";
$time = microtime(true);
$next = $chain->next($self, $params, $chain);
$time = microtime(true) - $time;
$count = 0;
while ($next->next())
$count++;
$next->rewind();
echo "Count: " . $count . "</br>\n";
echo "Time: " . $time . "</br>\n";
echo "=====================</br>\n";
return $next;
});
Based on all the suggestions by Nils and Mehdi I created a fresh plugin which will only show the query results and not the vardump or print_r() for the queries executed in Lithium with MongoDB.
It really now has become easier for me to find what it being executed.
You can take a look at the project at Github:
https://github.com/nilamdoc/li3_show

Magento foreach() orders getAllItems()

I am not sure why this loop is not working.
$orders = Mage::getSingleton('sales/order')->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('created_at', array('from'=>$from, 'to'=>$to))
->addAttributeToSort('increment_id', 'ASC')
;
foreach ($orders as $item) {
$order_id = $item->increment_id;
if (is_numeric($order_id)) $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
if (is_object($order)) {
echo "> O: ". $order_id ."<BR>";
$items = $order->getAllItems();
echo ">> O: ". $order_id ."<BR>";
} else
die("DIE ". var_dump($order));
}
die("<BR> DONE");
The output:
...
...
>> O: 100021819
> O: 100021820
>> O: 100021820
> O: 100021821
The loop never finishes nor does it stop at the same order_id.?
It always fails at $order->getAllItems()
These orders are either pending, processing or complete.
Is there something I should be checking for with $order->getAllItems(), since that's were it's failing.
Thanks.
Jon, I assume the problem you're talking about is your script ending un expectedly. i.e., you see the output with a single >
> O: 100021821
but not the output with the double >>.
Because Magento is so customizable, it's impossible to accurately diagnose your problem with the information given. Something is happening in your system, (a PHP error, an uncaught exception, etc.), that results in your script stopping. Turn on developer mode and set the PHP ini display_errors to 1 (ini_set('display_errors', 1);) and check your error log. One you (or we) have the PHP error, it'll be a lot easier to help you.
My guess is you're running into a memory problem. The way PHP has implemented objects can lead to small memory leaks — objects don't clean up after themselves correctly. This means each time you go through the loop you're slowly consuming the total amount of memory that's allowed for a PHP request. For a system with a significant number of orders, I'd be surprised if the above code could get through everything before running out of memory.
If your problem is a memory problem, there's information on manually cleaning up after PHP's objects in this PDF. You should also consider splitting your actions into multiple requests. i.e. The first request handles orders 1 - 100, the next 101 - 200, etc.
What do you mean it fails?
By the look of the output it doesn't fail there as it outputs text either side of the call to getAllItems()
change:
$items = $order->getAllItems();
to:
foreach($order->getAllItems() as $orderItem) {
echo $orderItem->getId() . "<br />";
}
and see what happens.
The script could be ending on a different order ID each time if you have a low memory limit set on the server and it quits when it runs out of resources.

Resources