I using Memcache to cache data in project yii2.
with config:
'cache' => [
'class' => 'yii\caching\MemCache',
'servers' => [
[
'host' => 'localhost',
'port' => 11211,
],
],
],
With code: return false
\Yii::$app->cache->set('abc', 'value of abc', 20); // 20 seconds
$data = \Yii::$app->cache->get('abc'); var_dump($data); // return false
But if i set:
\Yii::$app->cache->set('abc', 'value of abc', -20); // -20 seconds $data = \Yii::$app->cache->get('abc'); var_dump($data); // return "value of abc"
So why this? Thanks.
Can you increment the seconds?
Pls try this and let me know the results:
\Yii::$app->cache->set('abc', 'value of abc', 10000);
$data = \Yii::$app->cache->get('abc'); var_dump($data);
A bit late, but in case someone else have same problem, here are my thoughts...
It might depend on whether MemCached or MemCache is installed. If config uses MemCache (like in the question) but MemCached is installed, it will work using get() but set() is different after the two first parameters, ie duration.
Related
Locally everything works great:
Storage::fake('local');
$file = UploadedFile::fake()->image('watch.jpg');
$watchData = [
'model' => 'beatae unde adipisci',
'size' => '50',
'number' => 'm98300',
'metal' => 'deserunt',
'rrp' => '92840',
'status' => 'discontinued',
'brand_id' => '2',
'new_image' => $file,
];
$response = $this->post('/watch', $watchData);
Storage::disk('local')->assertExists('mg/jc-int/watch-images/1.jpg');
When I try to run this same test as part of my deployment workflow in GitHub Actions:
1) Tests\Feature\WatchImagesTest::test_a_watch_image_can_be_created
Unable to find a file or directory at path [mg/jc-int/watch-images/1.jpg].
Failed asserting that false is true.
I've tried a few things but I think this is more that I'm not understand how either Storage::fake() works or how GitHub actions handles filepaths?
Found the issue.
In my controller that handles the image upload, I'm grabbing a folder from my config:
$folder = config('site.DO_SUBFOLDER');
This value is taken from my .env and wasn't being included in the deployment pipeline.
Can someone explain to me how I can trigger Celery tasks through Logstash?
Is it possible?
If I try to do that in PHP through the 'php-amqplib' library it works fine: (without using Logstash)
$connection = new AMQPStreamConnection(
'rabbitmq.local',
5672,
'guest',
'guest'
);
$channel = $connection->channel();
$channel->queue_declare(
'celery',
false,
true,
false,
false
);
$taskId = rand(1000, 10000);
$props = array(
'content_type' => 'application/json',
'content_encoding' => 'utf-8',
);
$body = array(
'task' => 'process_next_task',
'lang' => 'py',
'args' => array('ktest' => 'vtest'),
'kwargs' => array('ktest' => 'vtest'),
'origin' => '#'.'mytest',
'id' => $taskId,
);
$msg = new AMQPMessage(json_encode($body), $props);
$channel->basic_publish($msg, 'celery', 'celery');
According to the Celery docs:
http://docs.celeryproject.org/en/latest/internals/protocol.html
I'm trying to send the request in the json format, this is my Logstash filter:
ruby
{
remove_field => ['headers', '#timestamp', '#version', 'host', 'type']
code => "
event.set('properties',
{
:content_type => 'application/json',
:content_encoding => 'utf-8'
})
"
}
And Celery answer is:
[2017-05-05 14:35:09,090: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!
{content_type:None content_encoding:None delivery_info:{'exchange': 'celery', 'routing_key': 'celery', 'redelivered': False, 'consumer_tag': 'None4', 'delivery_tag': 66} headers={}}
Basically, Celery is not able to decode my message format or better... I'm not able to set the request in the JSON format :)
It's driving me crazy, thank you in advance for any clues :)
Forgot it, this is my output plugin in Logstash
rabbitmq
{
key => "celery"
exchange => "celery"
exchange_type => "direct"
user => "${RABBITMQ_USER}"
password => "${RABBITMQ_PASSWORD}"
host => "${RABBITMQ_HOST}"
port => "${RABBITMQ_PORT}"
durable => true
persistent => true
codec => json
}
From the information provided in this question, you can't.
When you're playing with the event in the ruby filter, you're actually playing with what will be put in the body of the message, while you'd like to set the rabbitmq headers and properties of your message.
Till that functionality has been tackled, I do not think you'll be able to achieve it unless of course you implement it yourself. After all, the plugin is available on github.
As Olivier said, right now is not possible but I've created a pull request to the official project.
https://github.com/logstash-plugins/logstash-output-rabbitmq/pull/59
If you are looking for a working version take a look to my clone:
https://github.com/useless-stuff/logstash-output-rabbitmq
You should be seriously scared about that code :)
I'm completely far away to be a Ruby developer
But it works :)
How to properly create a custom configuration key in zend expressive
I tried to create a file custom-config.php in the config/autoload directory but the key is not read by the container
my custom-config.php looks like this
<?php
[
'customkey' => [
'value1' => '1',
'value2' => '2',
],
];
I think you a missing a return statement.
Try with
<?php
return [
'customkey' => [
'value1' => '1',
'value2' => '2',
],
];
Besides missing return statement, as marcosh pointed out, I think additional problem is the filename itself.
It should be something like custom-config.local.php or custom-config.global.php.
Configuration files are loaded in a specific order. First global.php, then *.global.php, local.php and finally *.local.php. This way local settings overwrite global settings.
Settings shared between servers go into *.global.php, sensitive data and local settings in *.local.php. Local config files are ignored by git.
The default loading behavior is set in config/config.php if you want to change this.
Your custom config could look like this:
<?php // config/autoload/custom-config.global.php
return [
'dependencies' => [
'invokables' => [
// ...
],
'factories' => [
// ...
],
],
// Prefered format
'vendor' => [
'package' => [
'key' => 'value',
]
],
// Custom package
'custom_package' => [
'value1' => '1',
'value2' => '2',
],
];
I am using server side processing, so as I understand, all sorting/ordering is done server side. However, when I click on the column header, it should send the server a post variable to apply the ASC or DESC sort order. This is not working and I'm trying to figure out where my problem lies.
I am using the default script that comes with datatables.
My dates in the database is stored as timestamp values such as 15-10-2015 10:20:30.
Now, the table displays fine, however the dates are not sorted correctly. Even if I output just the year values e.g. 2014 , it does not sort them ASC and DESC.
Instead, I get results like:
2014
2014
2015
2015
2014
2014
2015
:(
I declare the table as follows :
DemoTable = $('#table_demo').DataTable(
{
"order": [],
"aaSorting" : [],
"deferRender": true,
"bJQueryUI": true,
"bPaginate": true,
"bStateSave": true,
"processing": true,
"serverSide": true,
"sPaginationType": "full_numbers",
"ajax":
{
"url": "view_demo_remote.php",
"data":
{
"role": $_SESSION['role'],
"email": $_SESSION['email'],
"practiseid": $_SESSION['practiceid']
}
},
"columns":[
{ "data": "first_number" , "bSortable": true },
{ "data": "datecreated", "bSortable": true },
{ "data": "submitted_by"},
{ "data": "second_number"},
{ "data": "picture","bSortable": false },
{ "data": "options","bSortable": false }
],
});
On the server, I have the following section for the columns:
$columns = array(
array(
'db' => 'id',
'dt' => 'DT_RowId',
'formatter' => function( $d, $row )
{
// Technically a DOM id cannot start with an integer, so we prefix
// a string. This can also be useful if you have multiple tables
// to ensure that the id is unique with a different prefix
return $d;
}
),
array(
'db' => 'firstnumber',
'dt' => 'first_number',
'formatter' => function($d, $row)
{
$number = $d;
return substr($number, 0, 10);
}),
array(
'db' => 'datecreated',
'dt' => 'datecreated',
'formatter' => function($d, $row)
{
// DD/MM/YYYY HH:MM:SS
$date = date_create_from_format('d-m-Y H:i:s', $d);
return date_format($date, 'Y');
}),
array( 'db' => 'username', 'dt' => 'submitted_by' ),
array( 'db' => 'secondnumber', 'dt' => 'second_number' ),
array(
'db' => 'picture',
'dt' => 'picture',
'formatter' => function($d, $row)
{
return "<p style=\"padding:5px;\"><img src=\"".$d."\" alt=\"Picture\" style=\"width:auto;max-height:70px;border:1px solid #2d2d2d;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px; \"></img></p>";
}),
array( 'db' => 'id', 'dt' => 'options');
);
and then I have this part after the columns section:
// SQL server connection information
$sql_details = array(
'user' => DBUSER,
'pass' => DBUSERPASS,
'db' => DBNAME,
'host' => DBHOST
);
require( 'libraries/DataTables-1.10.7/examples/server_side/scripts/ssp.class.php' );
$whereAll = " firstnumber <>''";
echo json_encode(SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, "",$whereAll));
So the table displays fine, all column headers for the sortable columns can be clicked on and it sorts ASC or DESC perfectly. However, the date does not sort perfectly. If I turn off sorting off on the table and I manually add "ORDER BY datecreated ASC" to the where clause, it works perfectly, which tells me that there is nothing wrong with my date format, however, I want sorting ON.
Please help
I have also asked a question on the datatables forums https://www.datatables.net/forums/discussion/31216/datatables-not-ordering-date-correctly
Thanks all for contributing.
At the end of the day, the problem was actually caused by a field in the database that was in the wrong format. The datecreated field was saved as a Varchar and it had to be DATETIME.
Once I fixed this in the database, everything sorted perfectly.
thanks for everyone who helped. But yes, I want to stress the fact that when server side processing is being done, all sorting / ordering is done server side. You can manipulate the format and display on the client side, but NOT the actual order, when server side is being used.
I am trying to parse the JSON written # http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js
Here is a quick snippet from above link:
{vers:0.01,config:{rate:"perhr",valueColumns:["vCPU","ECU","memoryGiB","storageGB","sles"],currencies:["USD"],regions:[{region:"us-east",instanceTypes:[{type:"generalCurrentGen",sizes:[{size:"t2.micro",vCPU:"1",ECU:"variable",
...
...
...
...
Please visit the aforementioned link to see the complete JSON.
As seen above, none of the keys of above JSON have Double Quotes around them.
This leads to malformed JSON string and my JSON parser is failing at it. I also tried putting this JSON in http://www.jsoneditoronline.org/ and it fails as well.
Now, this is the same link which is used by Amazon to display various prices of their EC2 instance. So I think I am missing something here. My Googling led me to believe that above thing is not JSON and is instead JSONP.. I don't understand what is that.
Could you help me understand how to parse this JSON. BTW, I am doing this work in perl using JSON Module.
Some background:
Amazon Web Services does not have an API to get Pricing info programmatically. Hence I am parsing these links which is what amazon is doing while displaying pricing information here. Besides, I am not from programming space and perl is all I know.
Like you said JSONP or "JSON with padding" can't be parsed by json parser because it is not json (it is a different format). But it is actually a json with the prefix (padding)
The padding is typically the name of a callback function that wraps json.
In this case, its default callback names 'callback' and we can do a bit hackiest way by using Regular Expression to capture json that is wrapped by 'callback()' like this
s/callback\((.*)\);$/$1/s;
Also, if you would like to use JSON library, you can enable allow_barekey which means you don't need those quotes around those keys.
Below is my working code. I use LWP::Simple to get the content for the given and Data::Dump to print the isolated data structure.
use strict;
use warnings;
use LWP::Simple;
use JSON;
my $jsonp = get("http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js")
or die "Couldn't get url";
( my $json = $jsonp ) =~ s/callback\((.*)\);$/$1/s; #grap the json from $jsonp and store in $json variable
my $hash = JSON->new->allow_barekey->decode ( $json );
use Data::Dump;
dd $hash;
Outputs:
{
config => {
currencies => ["USD"],
rate => "perhr",
regions => [
{
instanceTypes => [
{
sizes => [
{
ECU => "variable",
memoryGiB => 1,
size => "t2.micro",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.023 } }],
vCPU => 1,
},
{
ECU => "variable",
memoryGiB => 2,
size => "t2.small",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.056 } }],
vCPU => 1,
},
{
ECU => "variable",
memoryGiB => 4,
size => "t2.medium",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.152 } }],
vCPU => 2,
},
{
ECU => 3,
memoryGiB => 3.75,
size => "m3.medium",
storageGB => "1 x 4 SSD",
valueColumns => [{ name => "os", prices => { USD => "0.170" } }],
vCPU => 1,
},
....
As said in comments above, it is not JSON so it can't be parsed by JSON parser... But for an quick & (very)dirty work, you can try the JSON::DWIW module.
The next code:
use 5.014;
use warnings;
use WWW::Mechanize;
use Data::Dump;
use JSON::DWIW;
my $mech = WWW::Mechanize->new();
my $jsonstr = $mech->get('http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js')->content;
($jsonstr) = $jsonstr =~ /callback\((.*)\)/s;
my $json_obj = JSON::DWIW->new;
my $data = $json_obj->from_json( $jsonstr );
dd $data;
prints a structure what maybe is what you want, e.g.:
{
config => {
currencies => ["USD"],
rate => "perhr",
regions => [
{
instanceTypes => [
{
sizes => [
{
ECU => "variable",
memoryGiB => 1,
size => "t2.micro",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.023 } }],
vCPU => 1,
},
{