stream_socket_client: truncates the data tape - sockets

I am using stream_socket_client to connect to the socket server. Using the fwrite() method, I write data there. Here is a sample code:
$localsocket = 'tcp://' . Yii::$app->params['socket.server'] . ':4002';
$message = [
'message' => $action,
'data' => $data
];
$instance = stream_socket_client($localsocket);
fwrite($instance, Json::encode(['user' => $token, 'message' => $message]) . "\r\n");
When the tape is not very large - everything works well. but when the tape is larger (an array of data encoded in json) - the server accepts the trimmed tape. at the same time, it cuts differently each time.
I did not find documentation on the limitation. could it be that fwrite() doesn't have time to write the data?

Related

Get Values out of Complex Perl Hash Structures

With the following Code I can fetch Data stored in a Hash from a Database and print it out:
use Data::Dumper;
my $fdx = $s->field(); # get Hashreference from Database
print Dumper($fdx); # print out Hash
The (important part of the) Output looks like this:
$VAR1 = bless( {
'selectable' => 'true',
'_PARENT_OBJECT' => bless( {
'dirtyFlag' => 1,
'path' => undef,
'testItems' => [],
'data' => {
'TEST_10' => {
'atm_rundatahistory' => {
'1523964918' => {
'atm_prid' => {
'content' => '',
'label' => 'Problem Report IDs',
'raw' => ''
}, ...
'1523964410' => {
'atm_prid' => {
'label' => 'Problem Report IDs',
'raw' => '23361234',
'content' => '23361234'
}, ...
'Test_10' is one of hundreds of Tests, '1523964918' is one of many unix timestamps, so basically its a 32 Bit Integer, but I dont know which numbers the timestamps contain.
How do I print out / access the values for 'content' (in this case '23361234') of the most inner Hashes, for all Tests and unix timestamps, if they exist?
from here on I will describe my thoughts and what I have tried, its not necessary to read any further for this question.
I think the code I am looking for is something like:
foreach my $val($fdx{_PARENT_OBJECT}{data}{"TEST_*"}{atm_rundatahistory}{"********"}{atm_prid}{content})
print("\n$val");
However I don't know the exact Syntax, and neither do I know which placeholders to set for "Test_10", since there are many tests numbers, e.g. "...Test_132...Test_134" and the Unix timestamps can be any 32 Bit Integer, so I guess I can use start as a placeholder? e.g. "********".
After some hours of searching on the web, I haven't found a understandable tutorial on how to access values from complex Perl hash structures, I guess there are some simple syntax-rules to know and you can get any value of even very complex data structures without to much effort.
I've already read perldoc_perlreftut. If there is any other easy to understandable tutorial for these kind of problems, please recommend them to me. I don't really know how I can learn to handle such complex data structures in Perl myself.

How to connecting RapidApp to PostgreSQL, with utf-8 enabled

I'm creating a simple CRUD interface to a database, and I'm trying RapidApp.
I have an existing database, which I connect to with existing Moose-based code. There is a complication in that there is UTF-8 text in the database (eg 'Encyclopédie médico-chirurgicale. Técnicas quirúrgicas. Aparato digestivo')
My Moose-based code works just fine: data goes in & data comes out... and everyone is happy.
In my existing Moose code, the connector is:
$schema = My::Service::Schema->connect(
'dbi:Pg:dbname=my_db;host=my.host.name;port=1234',
'me',
'secret',
{ pg_enable_utf8 => 1 }
);
When I set about connecting RapidApp, I first tried a simple rdbic.pl command, but that doesn't pick up the UTF-8 strings. In an attempt to enforce UTF-8-ness, I've created the following:
use Plack::Runner;
use Plack::App::RapidApp::rDbic;
my $cnf = {
connect_info => {
dsn => 'dbi:Pg:dbname=my_db;host=my.host.name;port=1234',
user => 'me',
password => 'secret',
{ pg_enable_utf8 => 1 },
},
schema_class => 'My::Service::Schema'
};
my $App = Plack::App::RapidApp::rDbic->new( $cnf );
my $psgi = $App->to_app;
my $runner = Plack::Runner->new;
$runner->parse_options('--port', '5678');
$runner->run($psgi);
(which is pretty much rdbic.pl, compressed to one specific thing)
However - I'm getting mal-formed strings (eg: 'Encyclopédie médico-chirurgicale. Técnicas quirúrgicas. Aparato digestivo')
Having fought to get the correct text INTO the database, I know the database is correct... so how do I connect RapidApp to get UTF-8 back out?
Your schema will need to be configured to support UTF-8. Here's a helpful set of things to try:
How to properly use UTF-8-encoded data from Schema inside Catalyst app?

How to capture actual POST data (the actual packet)?

In a Perl script I am POSTing the data using LWP::UserAgent->new. Could anyone please tell me how to capture the actual data packet before it actually posts the data?
This is how I POST:
my $response = $browser->post($authUrl,
[ 'username' => $username,
'response' => $pwdChallenge
]);
Thanks

Zend_Feed: white screen of death on Production, works perfectly on Dev Server

A few weeks ago I noticed that the RSS feed on my live site was broken - I get a white screen of death. It had worked fine up until then. The rest of my site continues to work fine. Additionally the identical code continues to work perfectly on my dev box.
No code changes have occurred, so I'm guessing my web host have changed a server setting - but I've no idea what the setting may be (so I don't know if there's a workaround or if I need to ask my web host to change something). Both Prod & Dev are running PHP 5.3.8.
Could anyone give me a clue as to what that setting might be?
The only major difference I could see in the response headers was that my (non-working) Production RSS feed has this Response Header: "Accept-Ranges: none".
I've double-checked the DB call that populates the feed, and even replaced it with some static data within the class (just in case there was a DB problem), but it makes no difference.
Code for the relevant Controller method below:
public function articlesAction(){
$format = $this->_request->getParam('format');
//default format to rss if unspecified
$format = in_array($format, array('rss','atom')) ? $format : 'rss';
$articles = new Application_Model_DbTable_Articles();
$rows = $articles->getLatestArticlesForFeed();
$channel = array(
'title' => 'Feed of articles',
'link' => 'http://www.mysite.co.uk',
'description' => 'The latest articles and reviews from my site',
'author' => 'My name',
'language' => 'en',
'ttl' => '60',
'copyright' => '© the writers of the articles',
'charset' => 'utf-8',
'entries' => array()
);
foreach ($rows as $item) {
$articlelink = 'http://www.mysite.co.uk/articles/' . $item['stub'];
$formattedlink = '<p><strong>Source: '.$articlelink.'</strong></p>';
$channel['entries'][] = array(
'title' => $item['title'],
'link' => $articlelink,
'guid' => $articlelink,
'description' => $formattedlink . $item['content'] . '<p>© ' . $item['byline'] . ', ' . $item['copyright'] . '</p>' ,
'lastUpdate' => strtotime($item['date_published'])
);
}
$feed = Zend_Feed::importArray($channel, $format);
$feed->__wakeup();
}
$feed->send();
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout()->disableLayout();
}
I wasted an hour once figuring out why I have a WSOD just because I initiated a class with one lowercase letter...
$table = new Model_DbTable_EshopSubcategories(); instead of
$table = new Model_DbTable_EshopSubCategories();
The dev server does not have to be case sensitive and the production server can.

How do I set up my POE::Filter to receive the entire chunk of data returned from the server?

I tried the following
my $filter = POE::Filter::Line->new(OutputLiteral => '');
my $wheel = POE::Wheel::ReadWrite->new(
Handle => $socket,
Filter => $filter,
InputEvent => 'on_input',
ErrorEvent => 'on_error',
FlushedEvent => 'on_flush',
);
But on_input is called several times with each line separately in ARG0. How do I get it all together? Doesn't setting setting OutputLiteral to '' change the filter's understanding of what a "line" is?
First of all, you are reading from the filter, so it's InputLiteral which is important here, not OutputLiteral. Second, you can't have an empty InputLiteral (if you try, it will just autodetect the input literal). Consequently, you can't use POE::Filter::Line to get all the data, because it is made for parsing line-terminated records. Use POE::Filter::Stream instead.