sonos
sonos copied to clipboard
PHP Soapclient memory issue
Hi, I'm using your great library to continuously check updates in the status of different Sonos speakers. However, I notice that the memory usage keeps increasing and it seems to be related to the PHP SoapClient.
If I go into the Device.php and comment the Soap call to get e.g. the volume status, the used memory stabilizes: $result = $soap->__soapCall($action, $soapParams);
Is this a known issue and what can I do about it?
Hi @koen-php, I've not come across this myself before, I'll do some investigation and see if I can reproduce.
If you could provide a small test script that demonstrates the issue that would be really helpful, thanks
Here is a simple CLI script that will get the volume of 1 speaker every second. In the output you will see the result and the current memory usage. On my device, the used memory increases on every iteration with 120:
<?php
require __DIR__ . '/vendor/autoload.php';
$i = 1;
while (true) {
echo "Iteration $i: - Memory usage: " . memory_get_usage() . "/" . memory_get_peak_usage() . "\n";
try {
$sonos = new duncan3dc\Sonos\Network(new Doctrine\Common\Cache\ArrayCache());
if ($sonos) {
$speaker = $sonos->getSpeakerByRoom('Woonkamer');
if ($speaker) {
echo "SUCCESS: Volume = " . $speaker->getVolume() . "\n";
}
else {
echo "FAIL: speaker is null\n";
}
}
else {
echo "FAIL: network is null\n";
}
}
catch (Exception $e) {
echo "FAIL: Exception = " . $e->getMessage() . "\n";
}
$i++;
sleep(1);
}
?>
I've tracked that to an issue in the PHP extension itself, but not been able to solve yet, I'll let you know once I get anywhere with upstream