Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from sj-i/improve-stability
Improve stability
- Loading branch information
Showing
32 changed files
with
384 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Lib\Defer; | ||
|
||
final class ScopeGuard | ||
{ | ||
public function __construct( | ||
private \Closure $callable, | ||
private ?ScopeGuard $chain = null, | ||
) { | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
($this->callable)(); | ||
if (isset($this->chain)) { | ||
unset($this->chain); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Lib\Defer; | ||
|
||
function defer(?ScopeGuard &$scope_guard, callable $function): void | ||
{ | ||
$scope_guard = new ScopeGuard( | ||
\Closure::fromCallable($function), | ||
$scope_guard ?? null | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Lib\File; | ||
|
||
use FFI; | ||
|
||
class NativeFileReader implements FileReaderInterface | ||
{ | ||
/** @var FFI\Libc\libc_file_ffi */ | ||
private FFI $ffi; | ||
|
||
public function __construct() | ||
{ | ||
/** @var FFI\Libc\libc_file_ffi */ | ||
$this->ffi = FFI::cdef(' | ||
int open(const char *pathname, int flags); | ||
ssize_t read(int fd, void *buf, size_t count); | ||
int close(int fd); | ||
'); | ||
} | ||
|
||
public function readAll(string $path): string | ||
{ | ||
$buffer = $this->ffi->new("unsigned char[4096]"); | ||
|
||
$fd = $this->ffi->open($path, 0); | ||
$result = ""; | ||
$done = false; | ||
do { | ||
$read_len = $this->ffi->read($fd, $buffer, 4096); | ||
if ($read_len > 0) { | ||
$result .= FFI::string($buffer, min($read_len, 4096)); | ||
} else { | ||
$done = true; | ||
} | ||
} while (!$done); | ||
$this->ffi->close($fd); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.