Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 2 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ script.php
<?php
require_once './vendor/autoload.php';

use Utopia\Console;
use Utopia\CLI\CLI;
use Utopia\CLI\Console;
use Utopia\CLI\Adapters\Generic;
use Utopia\Http\Validator\Wildcard;

Expand Down Expand Up @@ -52,7 +52,7 @@ There are three types of hooks, init hooks, shutdown hooks and error hooks. Init
require_once __DIR__ . '/../../vendor/autoload.php';

use Utopia\CLI\CLI;
use Utopia\CLI\Console;
use Utopia\Console;
use Utopia\Http\Validator\Wildcard;

CLI::setResource('res1', function() {
Expand Down Expand Up @@ -83,78 +83,10 @@ $cli
$cli->run();
```

### Log Messages

```php
Console::log('Plain Log'); // stdout
```

```php
Console::success('Green log message'); // stdout
```

```php
Console::info('Blue log message'); // stdout
```

```php
Console::warning('Yellow log message'); // stderr
```

```php
Console::error('Red log message'); // stderr
```

### Execute Commands

Function returns exit code (0 - OK, >0 - error) and writes stdout, stderr to reference variables. The timeout variable allows you to limit the number of seconds the command can run.

```php
$stdout = '';
$stderr = '';
$stdin = '';
$timeout = 3; // seconds
$code = Console::execute('>&1 echo "success"', $stdin, $stdout, $stderr, $timeout);

echo $code; // 0
echo $stdout; // 'success'
echo $stderr; // ''
```

```php
$stdout = '';
$stderr = '';
$stdin = '';
$timeout = 3; // seconds
$code = Console::execute('>&2 echo "error"', $stdin, $stdout, $stderr, $timeout);

echo $code; // 0
echo $stdout; // ''
echo $stderr; // 'error'
```

### Create a Daemon

You can use the `Console::loop` command to create your PHP daemon. The `loop` method already handles CPU consumption using a configurable sleep function and calls the PHP garbage collector every 5 minutes.

```php
<?php

use Utopia\CLI\Console;

include './vendor/autoload.php';

Console::loop(function() {
echo "Hello World\n";
}, 1 /* 1 second */);
```

## System Requirements

Utopia Framework requires PHP 7.4 or later. We recommend using the latest PHP version whenever possible.



## Copyright and license

The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
"utopia-php/di": "0.1.*"
},
"require-dev": {
"utopia-php/console": "0.0.*",
"phpunit/phpunit": "^9.3",
"squizlabs/php_codesniffer": "^3.6",
"phpstan/phpstan": "^1.10",
"laravel/pint": "1.2.*",
"swoole/ide-helper": "4.8.8"
},
"minimum-stability": "dev"


"minimum-stability": "dev",
"config": {
"allow-plugins": {
"php-http/discovery": true,
"tbachert/spi": true
}
}
}
Loading