Flare by Spatie
    • Error Tracking
    • Performance Monitoring
    • Logs
  • Pricing
  • Docs
  • Insights
  • Changelog
  • Back to Flare ⌘↵ Shortcut: Command or Control Enter
  • Sign in
  • Try Flare for free
  • Error Tracking
  • Performance Monitoring
  • Logs
  • Pricing
  • Docs
  • Insights
  • Changelog
    • Back to Flare ⌘↵ Shortcut: Command or Control Enter
    • Try Flare for free
    • Sign in
Flare Flare PHP PHP JavaScript JavaScript Protocol Protocol
PHP
  • Laravel
  • PHP
  • General
  • Installation
  • Integrating into a framework
  • Attribute providers
  • Application lifecycle
  • Censoring collected data
  • Ignoring collected data
  • Flare daemon
  • Errors
  • Introduction
  • Customise error report
  • Customising error grouping
  • Linking to errors
  • Logs
  • Introduction
  • Levels
  • With errors
  • Performance
  • Introduction
  • Sampling
  • Limits
  • Modify spans and events
  • Data Collection
  • Application info
  • Cache events
  • Console commands
  • Custom context
  • Database transactions
  • Dumps
  • Errors when tracing
  • Exception context
  • External http requests
  • Filesystem operations
  • Git information
  • Glows
  • Identifying users
  • Jobs and queues
  • Queries
  • Redis commands
  • Requests
  • Routing
  • Server info
  • Spans
  • Stacktrace arguments
  • Views
  • Older Packages
  • Flare Client PHP V2
  • Flare Client PHP V1

Filesystem operations

View as Markdown

Flare can collect information about the filesystem operations that your application executes.

You can disable this behaviour by calling ignoreFilesystem() on the Flare config:

$config->ignoreFilesystemOperations();

You can configure the maximum number of filesystem operations tracked while collecting data in the case of an error as such:

$config->collectFilesystemOperations(maxItemsWithErrors: 10);

Collecting filesystem operations

We cannot automatically collect filesystem operations in the framework-agnostic version of the package. You can manually add filesystem operations as such:

use Spatie\FlareClient\Enums\FilesystemOperation;

$flare->filesystem()->recordOperationStart(
    operation: FilesystemOperation::Exists,
    attributes:  [  
        'filesystem.path' => '/path/to/file.txt',
        
    ]
);

When the operation has finished, you should call the recordOperationEnd method:

$flare->filesystem()->recordOperationEnd(
    operation: FilesystemOperation::Exists,
    attributes:  [  
        'filesystem.exists' => true, 
    ]
);

To make things a bit easier, we've provided a few helper methods to make it easier to record common filesystem operations:

Path

Gets the full filesystem path of a local path:

$flare->filesystem()->recordPath('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method, you can pass a filesystem.full_path attribute with the full path of the file.

Exists

Checks if a file exists:

$flare->filesystem()->recordExists('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.exists attribute with the operation's result.

Get

Gets the contents of a file:

$flare->filesystem()->recordGet('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method, you can pass a filesystem.contents.size attribute with the size of the contents.

Put

Writes the contents to a file:

$flare->filesystem()->recordPut('/path/to/file.txt', 'Hello World');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Prepend

Writes the contents to a file at the beginning:

$flare->filesystem()->recordPrepend('/path/to/file.txt', 'Hello World');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Append

Writes the contents to a file at the end:

$flare->filesystem()->recordAppend('/path/to/file.txt', 'Hello World');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Delete

Deletes a file:

$flare->filesystem()->recordDelete('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Copy

Copies a file:

$flare->filesystem()->recordCopy('/path/to/file.txt', '/path/to/file-copy.txt');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Move

Moves a file:

$flare->filesystem()->recordMove('/path/to/file.txt', '/path/to/file-move.txt');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Size

Gets the size of a file:

$flare->filesystem()->recordSize('/path/to/file.txt');

When the operation has finished, you should call the recordOperationEnd method, you can pass a filesystem.contents.size attribute with the file size.

Files

Gets the files in a directory:

$flare->filesystem()->recordFiles('/path/to/directory');

When getting the files recursively, you can pass a recursive parameter to the recordFiles method:

$flare->filesystem()->recordFiles('/path/to/directory', recursive: true);

When the operation has finished, you should call the recordOperationEnd method, and you can pass a filesystem.found_paths attribute with the paths of the files.

Directories

Gets the directories in a directory:

$flare->filesystem()->recordDirectories('/path/to/directory');

When getting the directories recursively, you can pass a recursive parameter to the recordDirectories method:

$flare->filesystem()->recordDirectories('/path/to/directory', recursive: true);

When the operation has finished, you should call the recordOperationEnd method, and you can pass a filesystem.found_paths attribute with the paths of the directories.

Make Directory

Creates a directory:

$flare->filesystem()->recordMakeDirectory('/path/to/directory');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

Delete Directory

Deletes a directory:

$flare->filesystem()->recordDeleteDirectory('/path/to/directory');

When the operation has finished, you should call the recordOperationEnd method. You can pass a filesystem.operation.success attribute with the operation's result.

External http requests Git information

On this page

  • Collecting filesystem operations

Catch errors and fix slowdowns with Flare, the full-stack application monitoring platform for Laravel, PHP & JavaScript.

  • Platform
  • Error Tracking
  • Performance Monitoring
  • Pricing
  • Support
  • Resources
  • Insights
  • Newsletter
  • Changelog
  • Documentation
  • Affiliate program
  • uptime status badge Service status
  • Terms of use
  • DPA
  • Privacy & cookie Policy
Made in by Spatie logo
Flare