From 3a75f15ca33c8dd73b976b07c450ded4233ff123 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 10 Apr 2015 09:16:28 +0200 Subject: [PATCH 1/3] add example file close smbclient connections properly --- .gitignore | 1 + example.php | 20 ++++++++++++++++++++ src/RawConnection.php | 14 ++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 example.php diff --git a/.gitignore b/.gitignore index 3ce5adb..4f38912 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea vendor +composer.lock diff --git a/example.php b/example.php new file mode 100644 index 0000000..b8fac6c --- /dev/null +++ b/example.php @@ -0,0 +1,20 @@ +getShare('test'); + +$share->put(__FILE__, 'example.php'); + +$files = $share->dir('/'); +foreach ($files as $file) { + echo $file->getName() . "\n"; +} diff --git a/src/RawConnection.php b/src/RawConnection.php index 926ce37..89728a4 100644 --- a/src/RawConnection.php +++ b/src/RawConnection.php @@ -149,6 +149,20 @@ class RawConnection { return; } if ($terminate) { + $status = proc_get_status($this->process); + $ppid = $status['pid']; + $pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`); + foreach($pids as $pid) { + if(is_numeric($pid)) { + // try for case that posix_ functions are not available + try { + //9 is the SIGKILL signal + posix_kill($pid, 9); + } catch (\Exception $e) { + throw $e; + } + } + } proc_terminate($this->process); } proc_close($this->process); From 0cfbf3367133ed63fb2a1796738ba4efb764ca28 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 10 Apr 2015 09:17:55 +0200 Subject: [PATCH 2/3] Changed from try/catch to if(function_exists()) --- src/RawConnection.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/RawConnection.php b/src/RawConnection.php index 89728a4..1547851 100644 --- a/src/RawConnection.php +++ b/src/RawConnection.php @@ -149,17 +149,15 @@ class RawConnection { return; } if ($terminate) { - $status = proc_get_status($this->process); - $ppid = $status['pid']; - $pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`); - foreach($pids as $pid) { - if(is_numeric($pid)) { - // try for case that posix_ functions are not available - try { + // if for case that posix_ functions are not available + if (function_exists('posix_kill')) { + $status = proc_get_status($this->process); + $ppid = $status['pid']; + $pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`); + foreach($pids as $pid) { + if(is_numeric($pid)) { //9 is the SIGKILL signal posix_kill($pid, 9); - } catch (\Exception $e) { - throw $e; } } } From 99f1289b28700f4b3b4c078167023fd39da94b14 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 10 Apr 2015 09:19:48 +0200 Subject: [PATCH 3/3] Changed from try/catch to if(function_exists()) (reverted from commit 0cfbf3367133ed63fb2a1796738ba4efb764ca28) --- src/RawConnection.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/RawConnection.php b/src/RawConnection.php index 1547851..89728a4 100644 --- a/src/RawConnection.php +++ b/src/RawConnection.php @@ -149,15 +149,17 @@ class RawConnection { return; } if ($terminate) { - // if for case that posix_ functions are not available - if (function_exists('posix_kill')) { - $status = proc_get_status($this->process); - $ppid = $status['pid']; - $pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`); - foreach($pids as $pid) { - if(is_numeric($pid)) { + $status = proc_get_status($this->process); + $ppid = $status['pid']; + $pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`); + foreach($pids as $pid) { + if(is_numeric($pid)) { + // try for case that posix_ functions are not available + try { //9 is the SIGKILL signal posix_kill($pid, 9); + } catch (\Exception $e) { + throw $e; } } }