- Can I use spatie/wordpress-ray in a Laravel + WordPress mixed project (e.g., Laravel as a REST API for WordPress)?
- Yes, the package works seamlessly in mixed stacks. Since Ray supports PHP debugging across frameworks, you can use the same `ray()` helper in both Laravel and WordPress codebases. This reduces context-switching and lets you debug API interactions or shared logic consistently. Just ensure your Ray server is accessible from both environments.
- How do I install spatie/wordpress-ray in a WordPress project? Does it require Composer?
- Installation is via Composer: run `composer require spatie/wordpress-ray`. The package integrates automatically with WordPress’s shutdown hook and doesn’t require manual configuration. If your WordPress project doesn’t use Composer (e.g., traditional WP installs), you’ll need to set up a Composer-based workflow, like Bedrock or Sage, to use this package.
- Will this package conflict with existing WordPress debugging tools like Query Monitor or WP_DEBUG_LOG?
- Potential conflicts exist if both tools output to the same stream (e.g., `WP_DEBUG_LOG`). Test with `WP_DEBUG_DISPLAY=false` and `WP_DEBUG_LOG=true` to avoid duplication. Ray captures output independently, so conflicts are rare unless plugins/themes override `ob_start()`. Use conditional logging (e.g., `if (WP_ENV === 'local') ray(...)`) to mitigate overlaps.
- Does spatie/wordpress-ray work with WordPress multisite installations?
- Yes, but configuration may vary per subsite. If using a shared Ray server, ensure all subsites can reach it. For isolated debugging, configure Ray per subsite or use environment-specific flags (e.g., `define('RAY_ENABLED', true)` in `wp-config.php`). Test with a staging multisite to validate output capture across subsites.
- What Laravel versions or PHP dependencies does this package require?
- The package requires **PHP 8.1+** (due to Ray’s dependencies) and **WordPress 5.0+**. While it’s designed for WordPress, it leverages Ray’s PHP library, which is also used in Laravel. If your Laravel app uses PHP 8.0 or lower, you’ll need to upgrade or use Ray’s legacy mode, which may have limited features.
- How do I enable/disable Ray debugging in production or staging environments?
- Use WordPress constants or environment variables to control Ray. Add `define('RAY_ENABLED', false)` to `wp-config.php` for production, or use `.env` files in Composer-based setups. For staging, enable it conditionally: `if (WP_ENV === 'staging') ray(...);`. Avoid enabling Ray in production to prevent debug data leakage.
- Can I measure performance or profile execution time in WordPress with this package?
- Yes, Ray includes built-in performance tools. Use `ray()->measure('operation_name', fn() => $your_code)` to profile execution time, or `ray()->pause()` to inspect state mid-execution. This is especially useful for debugging slow queries, plugins, or custom REST APIs in WordPress.
- What happens if the Ray server is down or unreachable? Will debug messages still work?
- By default, Ray messages are sent synchronously, so a downed server may block execution. To handle failures, configure a fallback (e.g., log to `WP_DEBUG_LOG`) or use async workers like Laravel Queues to offload Ray traffic. The package doesn’t include built-in fallbacks, so you’ll need to implement them via custom error handling.
- Are there any alternatives to spatie/wordpress-ray for debugging WordPress?
- Yes, alternatives include **Query Monitor** (plugin for SQL/hook debugging), **Xdebug** (PHP-level debugging), or **Laravel’s built-in `dump()` with Tail** (for CLI output). However, Ray stands out for its **cross-language support**, **desktop UI**, and **consistent API** across Laravel/WordPress. If you’re already using Ray in Laravel, this package extends that workflow to WordPress.
- How do I send HTML, arrays, or files to Ray from WordPress?
- Use the `ray()` helper like in Laravel: `ray($your_variable)` works for arrays, objects, and strings. For HTML, pass the rendered output directly: `ray($post->post_content)`. To send files (e.g., logs), use `ray()->file('/path/to/file.log')`. Ray’s UI renders these types interactively, including collapsible arrays and syntax-highlighted code.