You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Diffbot client not closing TCP connections until client exits #58
While not too bad for a single socket, if you create a lot of diffbot objects using new Diffbot(), you can quickly run out of open files on the system as the sockets aren't closed even when the object falls out of scope.
I wrote a wrapper for the Diffbot client which implemented a singleton and this has resolved the issue for me.
<?php
namespace DDA;
class Diffbot
{
private static $instance;
private function __construct() {}
private static $apiKey = "sadffddsfafafdfdsdfsdfs";
/**
* @return \Swader\Diffbot\Diffbot
* @throws \Zend_Exception
*/
public static function getInstance(): \Swader\Diffbot\Diffbot
{
if(self::$instance === null) {
self::$instance = new \Swader\Diffbot\Diffbot(self::$apiKey);
}
return self::$instance;
}
}
So I would propose that rather than calling new Diffbot(),each time you call the wrapped static method getInstance() which returns the singleton instance.
While the root cause - dangling TCP connections - is still there, it's only a single one, from the single Diffbot object, being re-used extensively, even when updating thousands of searches.
I would propose a similar approach is taken within your library.
Activity
jonathantullett commentedon Dec 3, 2017
I wrote a wrapper for the Diffbot client which implemented a singleton and this has resolved the issue for me.
So I would propose that rather than calling
new Diffbot(),each time you call the wrapped static methodgetInstance()which returns the singleton instance.While the root cause - dangling TCP connections - is still there, it's only a single one, from the single Diffbot object, being re-used extensively, even when updating thousands of searches.
I would propose a similar approach is taken within your library.