{"id":25878598,"url":"https://github.com/potherca-blog/php-timecop-example","last_synced_at":"2026-06-13T09:02:38.542Z","repository":{"id":147392490,"uuid":"257224977","full_name":"potherca-blog/php-timecop-example","owner":"potherca-blog","description":"http://blog.pother.ca/php-timecop-example/ Examples demonstrating how PHP TimeCop works","archived":false,"fork":false,"pushed_at":"2024-06-01T23:41:28.000Z","size":48,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-29T23:09:55.097Z","etag":null,"topics":["blog-article","example","example-app","example-code","example-codes","example-project","example-projects","example-repo","examples","examples-php","php","php-example","php-examples","php-extensions","php-module","php-modules","php-timecop","potherca","potherca-blog","timecop"],"latest_commit_sha":null,"homepage":"https://php-timecop.glitch.me/","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/potherca-blog.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-04-20T08:57:33.000Z","updated_at":"2025-01-29T14:46:43.000Z","dependencies_parsed_at":"2023-05-22T12:00:36.077Z","dependency_job_id":null,"html_url":"https://github.com/potherca-blog/php-timecop-example","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/potherca-blog/php-timecop-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potherca-blog%2Fphp-timecop-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potherca-blog%2Fphp-timecop-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potherca-blog%2Fphp-timecop-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potherca-blog%2Fphp-timecop-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/potherca-blog","download_url":"https://codeload.github.com/potherca-blog/php-timecop-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potherca-blog%2Fphp-timecop-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34278154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["blog-article","example","example-app","example-code","example-codes","example-project","example-projects","example-repo","examples","examples-php","php","php-example","php-examples","php-extensions","php-module","php-modules","php-timecop","potherca","potherca-blog","timecop"],"created_at":"2025-03-02T12:35:20.815Z","updated_at":"2026-06-13T09:02:38.536Z","avatar_url":"https://github.com/potherca-blog.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![PHP TimeCop Logo](logo-timecop.png)\n\n\u003e _\"There is never enough time.\"_\n\u003e ~ Max Walker\n\n[![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b/remix-button.svg)](https://glitch.com/edit/#!/remix/php-timecop)\n\n## Introduction\n\nThe [php-timecop](https://github.com/hnw/php-timecop) PHP extension\nmakes it possible to manipulate time as experienced by the PHP runtime.\n\nIt provides \"time travel\" and \"time freezing\" capabilities.\n\nThis can be very useful when testing code that has time-sensitive functionality.\n\nThis project offers examples demonstrating how PHP TimeCop works.\n\nIt can be seen in action at https://php-timecop.glitch.me/\n\nTo play around with it, [remix this project on Glitch](https://glitch.com/edit/#!/remix/php-timecop).\n\n## Usage\n\n1. [Install php-timecop](https://github.com/hnw/php-timecop#install-with-package-manager) on a PHP server of your choice.\n2. Clone this repository to the same server.\n3. Visit the `index.php` in a web browser.\n4. Study the provided examples and their output.\n5. ...\n6. [Profit!](http://knowyourmeme.com/memes/profit)\n\n## Features\n\nPHP TimeCop offers four functions to manipulate time.\n\nFor the static class method a regular function is also available (execept for `return` as that is a reserved word in PHP):\n\n-   `TimeCop::freeze($new_time)` / `timecop_freeze($new_time)`\n-   `timecop_return()`\n-   `TimeCop::scale($scaling_factor)` / `timecop_scale($scaling_factor)`\n-   `TimeCop::travel($new_time)` / `timecop_travel($new_time)`\n\n### Freeze\n\nUsed to statically mock the concept of \"now\".\n\nAs the PHP runtime executes, `time()` will not change unless subsequent calls to freeze/return/scale/travel are made.\n\n### Return\n\nReturn the system to a normal state. Effectively \"turn off\" php-timecop\n\n### Scale\n\nMake time move at an accelerated pace. With this function, long time spans can be emulated in a shorter time.\n\n### Travel\n\nComputes an offset between the currently think `time()` and the time passed in. It uses this offset to simulate the passage of time.\n\n## Examples\n\nThe result of these examples can be seen below.\n\n### Freeze\n\n```php\n\u003c?php\n$new_time = isset($_GET['time'])?strtotime($_GET['time']):0;\nvar_dump(date('Y-m-d H:i:s')); // todays date\nTimecop::freeze($new_time);\nvar_dump(date('Y-m-d H:i:s'));\n```\n\n### Return\n\n```php\n\u003c?php\n$new_time = isset($_GET['time'])?strtotime($_GET['time']):0;\nTimecop::freeze($new_time);\nsleep(1);\nvar_dump(date('Y-m-d H:i:s'));\ntimecop_return(); // \"turn off\" php-timecop\nsleep(1);\nvar_dump(date('Y-m-d H:i:s'));\n```\n\n### Scale\n\n```php\n\u003c?php\n$new_time = isset($_GET['time'])?strtotime($_GET['time']):0;\nTimecop::freeze(new DateTime('@' . $new_time));\nvar_dump((new DateTime())-\u003eformat('Y-m-d H:i:s'));\nTimecop::scale(86400); // time passes at one day per second\nsleep(1);\nvar_dump((new DateTime())-\u003eformat('Y-m-d H:i:s'));\nsleep(1);\nvar_dump((new DateTime())-\u003eformat('Y-m-d H:i:s'));\n```\n\n### Travel\n\n```php\n\u003c?php\n$new_time = isset($_GET['time'])?strtotime($_GET['time']):0;\nTimecop::freeze($new_time);\nvar_dump(date('Y-m-d H:i:s'));\nsleep(1);\nvar_dump(date('Y-m-d H:i:s'));\nTimecop::travel($new_time);\nsleep(1);\nvar_dump(date('Y-m-d H:i:s'));\n```\n\n## Example Output\n\nBelow is the output of the examples mentioned above.\n\n### Freeze\n\n```\nstring '2018-05-24 16:41:29' (length=19)\nstring '2008-07-31 00:00:00' (length=19)\n```\n\n### Return\n\n```\nstring '2008-07-31 00:00:00' (length=19)\nstring '2018-05-24 16:41:31' (length=19)\n```\n\n### Scale\n\n```\nstring '2008-07-31 00:00:00' (length=19)\nstring '2008-08-01 00:00:11' (length=19)\nstring '2008-08-02 00:00:37' (length=19)\n```\n\n### Travel\n\n```\nstring '2008-07-31 00:00:00' (length=19)\nstring '2008-07-31 00:00:00' (length=19)\nstring '2008-08-01 00:00:12' (length=19)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotherca-blog%2Fphp-timecop-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpotherca-blog%2Fphp-timecop-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotherca-blog%2Fphp-timecop-example/lists"}