{"id":15022097,"url":"https://github.com/juan-morales/footprint-php","last_synced_at":"2025-07-15T14:09:56.067Z","repository":{"id":56997427,"uuid":"325540163","full_name":"juan-morales/footprint-php","owner":"juan-morales","description":"composer package that allows you monitor/trace/get custom data about your running php script and generate a report with it.","archived":false,"fork":false,"pushed_at":"2021-03-05T08:12:12.000Z","size":548,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T06:13:11.176Z","etag":null,"topics":["composer","footprint","footprint-php","jcm","jcmargentina","juan","morales","package","php","statistics","trace"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juan-morales.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-30T12:03:38.000Z","updated_at":"2022-04-27T06:49:02.000Z","dependencies_parsed_at":"2022-08-21T11:10:19.094Z","dependency_job_id":null,"html_url":"https://github.com/juan-morales/footprint-php","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juan-morales%2Ffootprint-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juan-morales%2Ffootprint-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juan-morales%2Ffootprint-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juan-morales%2Ffootprint-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juan-morales","download_url":"https://codeload.github.com/juan-morales/footprint-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525138,"owners_count":21118619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","footprint","footprint-php","jcm","jcmargentina","juan","morales","package","php","statistics","trace"],"created_at":"2024-09-24T19:57:27.228Z","updated_at":"2025-04-12T06:13:19.967Z","avatar_url":"https://github.com/juan-morales.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# footprint-php\n\n![Latest Stable Version](https://img.shields.io/packagist/v/jcm/footprint-php)\n![Latest Release Version](https://img.shields.io/github/v/release/juan-morales/footprint-php)\n![Total Downloads](https://img.shields.io/packagist/dt/jcm/footprint-php)\n![License](https://img.shields.io/packagist/l/jcm/footprint-php)\n\nComposer package that allows you to trace/monitor and retrieve/calculate/generate custom stats about your running php script.\n\nIt is build in a modular way and event triggers, really easy to follow and customize.\n\nThe package already comes with some modules likes:\n\n-   ChartJS line chart report (output only)\n-   CSV report (log and output)\n-   Time tracking (log)\n-   Memory tracking (log)\n\nCode is really simple and short, so you can quickly pick it up and create your own code.\n\n# Quick intro\n\n## Installation\n\n```\ncomposer require jcm/footprint-php\n```\n\n## Step by Step usage example and output\n\nIn this code we want to measure how much time and memory a function call or class method uses.\n\n\nKeep in mind that is a demo example, **you will not have to initialize more than once if you code properly**.\n\nBasically in the example we create a class called `SomeClassName` with a method called `testMethod` and we are gonna measure time and memory usage of this method when its called.\n\nWe will do this example by creating a php project from scratch, if you already have a project, adjust the example to your needs.\n\n#### Step 1: Create a php project with composer\n\nRun `composer init` and create a **project** , name it as you want.\n\nWhile the wizard asks you different questions about the project, it will ask you about what dependencies you want to install, leave it blank for now.\n\nIt looks something like this:\n`Would you like to define your dependencies (require) interactively [yes]? no` answer no.\n\n#### Step 2: Install footprint-php package\n\nRun `composer require jcm/footprint-php`\n\nYou should get an output like this:\n\n```\nUsing version ^1.1 for jcm/footprint-php\n./composer.json has been updated\nRunning composer update jcm/footprint-php\nLoading composer repositories with package information\nUpdating dependencies\nLock file operations: 1 install, 0 updates, 0 removals\n  - Locking jcm/footprint-php (v1.1)\nWriting lock file\nInstalling dependencies from lock file (including require-dev)\nPackage operations: 1 install, 0 updates, 0 removals\n  - Installing jcm/footprint-php (v1.1): Extracting archive\nGenerating autoload files\n```\n\n#### Step 4: Create an index.php with our code\n\nRun `touch index.php`\n\nWith the following code inside\n\n```php\n\u003c?php declare(strict_types = 1);\n\nrequire(\"vendor/autoload.php\");\n\nuse Footprint\\Tracker;             //For the main Tracker instance\nuse Footprint\\Modules\\ChartJS;     //Tracker module\nuse Footprint\\Modules\\Memory;      //Tracker module\nuse Footprint\\Modules\\Time;        //Tracker module\n\nclass SomeClassName \n{\n    public function testMethod() {\n        $mem = str_repeat(\"X\", 1024 * 1024); //We create a variable using certain memory size\n        \n        $moduleTime = new Time();  //Create instance of the Time module\n        $moduleMem = new Memory(); //Create instance of the Memory module\n        \n        /**\n         * We create an instance of the ChartJS module\n         * and we also specify the name of the output file that it will generate for us\n         */\n        $moduleChartJS = new ChartJS(\"report.html\");\n\n        /**\n         * Module ChartJS needs to know in advance which \"Tracker keys\" will\n         * consider at the moment of generating the chart for us.\n         * \n         * You can read more about this in the Wiki section, but basically we are adding all\n         * the keys used in the Memory and Time modules.\n         */\n        foreach($moduleMem-\u003egetKeys() as $key) {\n            $moduleChartJS-\u003eaddKey($key);\n        }\n\n        foreach($moduleTime-\u003egetKeys() as $key) {\n            $moduleChartJS-\u003eaddKey($key);\n        }\n        \n        $tracker = new Tracker(); //Main Tracker instance\n        \n        /**\n         * We load the previously created modules into the Tracker.\n         * \n         * The Tracker is the main actor in all this scenario.\n         * \n         * The Tracker will use the modules properly.\n         */\n        $tracker-\u003eloadModule($moduleMem);\n        $tracker-\u003eloadModule($moduleTime);\n        $tracker-\u003eloadModule($moduleChartJS);\n        \n        $tracker-\u003einit(); //Start the Tracker\n        \n        $tracker-\u003elog(); //We do our first log\n        \n        /**\n         * Now we will ...\n         * 1) Increase the memory use by the $mem variable\n         * 2) Make some sleeps to generate a delay\n         * \n         * All these is done trying to simulate a real php code execution, that uses\n         * different amount of memory and time execution.\n         * \n         */\n\n        $mem = str_repeat($mem, 2); //We duplicate the size of memory use by variable $mem\n        \n        sleep(1); //Wait 1 second\n        \n        $tracker-\u003elog(); //Log again\n        \n        sleep(2);\n        \n        $mem = str_repeat($mem, 2);\n        \n        $tracker-\u003elog();\n        \n        sleep(1);\n        \n        $mem = str_repeat(\"XXX\", 2000);\n        \n        $tracker-\u003elog();\n        \n        /**\n         * When we get to the point we dont want to track anymore, then we finalize tracking calling\n         * the end() method of the Tracker.\n         */\n        $tracker-\u003eend();\n    }\n}\n\n$testClass = new SomeClassName();\n\n$testClass-\u003etestMethod();\n\necho \"End here\";\n\n```\n\n\n#### Step 5: Execute the example\n\nFrom the command line run `php -f index.php`\n\n#### Step 6: Check the results\n\nIf everything went ok, then you should have a file called `report.html`, and the content should look something like this:\n\n![Output report using ChartJS](https://github.com/juan-morales/footprint-php/blob/main/output_example.jpg \"Output with ChartJS\")\n\n\n# Why this package?\n\nThis package was created in order to have a simple and small package, customizable, that could allow you to retrieve data while you execute your php scripts.\n\n# Documentation (Work in progress)\n\nPlease refer to the wiki section of the project to learn more about the package design, usage, and how to extend it.\n\n# Contributing to the project\n\nEven though I am working on this package in order to improve it, feel free to open issues, send pull requests, creating new modules or enhancing the existing ones, etc. \n\nIt is possible to create advance modules (like a live dashboard with websocket connection to update data on it, so we can have a real-time dashboard, etc.), but for the first release of this package I wanted to keep it simple and functional.\n\n**All kind of help is welcome**\n\n# Autor\n\nJuan Carlos Morales \u003cjcmargentina@gmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuan-morales%2Ffootprint-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuan-morales%2Ffootprint-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuan-morales%2Ffootprint-php/lists"}