Skip to content

Commit 559eea4

Browse files
authored
Merge pull request #154 from splitio/fix/sharedMemory
Fix/shared memory
2 parents f915233 + 85dad13 commit 559eea4

File tree

8 files changed

+45
-7
lines changed

8 files changed

+45
-7
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
6.2.5 (Apr 22, 2021)
2+
- Added delimiter in SharedMemory Cache.
3+
4+
6.2.4 (Mar 20, 2020)
5+
- Added missing methods in ClientInterface.
6+
17
6.2.3 (Nov 1, 2019)
28
- Added flag `IPAddressesEnabled` into options to enable/disable sending MachineName and MachineIP when data is posted in headers.
39

Detailed-README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ $splitClient = $splitFactory->client();
391391
Within tests folder you can find different test suites in order to run the Split SDK tests. The most important test suite is: **integration** that wrap the others test suites.
392392

393393
### Integration test suite
394-
Before to run this test suite, please be sure to have a Redis instance runing:
394+
Before to run this test suite, please be sure to have a Redis instance running:
395395
- In order to have a local Redis instance you can install [Docker Container Tool](https://www.docker.com) and pull the oficial Redis container running the command ```docker pull redis```.
396396

397397
And set the correct values on the **phpunit.xml** that you should have copied from **phpunit.xml.dist** file.

src/SplitIO/Component/Common/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static function stop($throw = false)
7474
}
7575

7676
/**
77-
* Method to add the catched error
77+
* Method to add the caught error
7878
* @param $errno
7979
* @param string $errstr
8080
* @param string $errfile

src/SplitIO/Component/Memory/SharedMemory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function write($key, $value, $expiration = 60, $mode = 0644, $size
3737

3838
$expiration = time() + $expiration;
3939

40-
$data = json_encode(array('expiration' => $expiration, 'value' => serialize($value)));
40+
$data = json_encode(array('expiration' => $expiration, 'value' => serialize($value))) . "\0";
4141

4242
@$shm_id = shmop_open($key, "c", $mode, $size);
4343

@@ -87,7 +87,11 @@ public static function read($key, $mode = 0644, $size = 100)
8787
throw new ReadSharedMemoryException("The shared memory block could not be read");
8888
}
8989

90-
$data = json_decode($cached_string, true);
90+
$null_pos = strpos($cached_string, "\0");
91+
$data = json_decode(
92+
substr($cached_string, 0, $null_pos),
93+
true
94+
);
9195

9296
if ((isset($data['expiration']) && time() > $data['expiration']) || !isset($data['expiration'])) {
9397
shmop_delete($shm_id);

src/SplitIO/Sdk/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private function registerData($impressions, $attributes, $metricName, $latency =
254254
}
255255
} catch (\Exception $e) {
256256
SplitApp::logger()->critical(
257-
': An exception occured when trying to store impressions.'
257+
': An exception occurred when trying to store impressions.'
258258
);
259259
}
260260
}

src/SplitIO/Sdk/Evaluator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private function evalTreatment($key, $bucketingKey, $split, array $attributes =
117117
}
118118
SplitApp::logger()->info("*Treatment for $key in {$split->getName()} is: ".$result['treatment']);
119119
} catch (\Exception $e) {
120-
SplitApp::logger()->critical('An exception occured when evaluating feature: '. $split->getName());
120+
SplitApp::logger()->critical('An exception occurred when evaluating feature: '. $split->getName());
121121
SplitApp::logger()->critical($e->getMessage());
122122
SplitApp::logger()->critical($e->getTraceAsString());
123123
$result['impression']['label'] = ImpressionLabel::EXCEPTION;

src/SplitIO/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
class Version
55
{
6-
const CURRENT = '6.2.4';
6+
const CURRENT = '6.2.5-rc1';
77
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
namespace SplitIO\Test\Suite\Component\Memory;
3+
4+
use SplitIO\Component\Memory\SharedMemory;
5+
6+
class SharedMemoryTest extends \PHPUnit_Framework_TestCase
7+
{
8+
public function testSharedMemoryOperations()
9+
{
10+
if (!extension_loaded('shmop')) {
11+
$this->markTestSkipped(
12+
'The shmop extension is not available.'
13+
);
14+
}
15+
16+
$key = 1234;
17+
$value = 'bar';
18+
19+
SharedMemory::write($key, $value);
20+
$given = SharedMemory::read($key);
21+
$this->assertEquals($value, $given);
22+
23+
$updated_value = 'new_value';
24+
SharedMemory::write($key, $updated_value);
25+
$given = SharedMemory::read($key);
26+
$this->assertEquals($updated_value, $given);
27+
}
28+
}

0 commit comments

Comments
 (0)