承接 upscale/stdlib-object-lifecycle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

upscale/stdlib-object-lifecycle

Composer 安装命令:

composer require upscale/stdlib-object-lifecycle

包简介

Library to monitor lifecycle of objects allocated by long-running PHP scripts

README 文档

README

This library tracks existence of objects throughout their lifecycle until eventual destruction. It can accurately detect memory leaks in long-running CLI scripts or event-driven web-servers, such as Swoole or ReactPHP.

The monitoring can be easily activated for applications with centralized object instantiation, i.e. using a DI container.

Features:

  • Watch any object w/o modifying its source code
  • Detect objects that are still alive
  • Detect objects that have been destroyed
  • Debug info on alive/destroyed objects: class, hash, trace
  • Garbage collection of circular references

Installation

The library is to be installed via Composer as a dependency:

composer require upscale/stdlib-object-lifecycle

Usage

Detect destruction of objects:

$obj1 = new \stdClass();
$obj2 = new \stdClass();
$obj3 = new \stdClass();

// Circular references subject to garbage collection
$obj1->ref = $obj2;
$obj2->ref = $obj1;

$watcher = new \Upscale\Stdlib\Object\Lifecycle\Watcher();
$watcher->watch($obj1);
$watcher->watch([$obj2, $obj3]);

unset($obj1);

// Outputs 3 because of circular references
echo count($watcher->detectAliveObjects());

unset($obj2);

// Outputs 3 because of pending garbage collection 
echo count($watcher->detectAliveObjects(false));

// Outputs 1 after forced garbage collection 
echo count($watcher->detectAliveObjects());

unset($obj3);

// Outputs 0 and 3 respectively
echo count($watcher->detectAliveObjects());
echo count($watcher->detectGoneObjects());

Methods detectAliveObjects() and detectGoneObjects() return the following debug information:

array(
  array(
    'type' => 'stdClass',
    'hash' => '00000000524c32e1000000002cee0034',
    'trace' => '#0 demo.php(26): Upscale\\Stdlib\\Object\\Lifecycle\\Watcher->watch(Object(stdClass))
#1 demo.php(10): Example->runTest()
#2 demo.php(53): Example->test()
#3 {main}',
  ),
  ...
)

Contributing

Pull Requests with fixes and improvements are welcome!

License

Licensed under the Apache License, Version 2.0.

统计信息

  • 总下载量: 37
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-08-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固