Scratchpad
The Scratchpad runs PHP code in your project, with your framework fully booted. Use it to query data, try an API, or test a service without writing a route or a test. You can run code in your DDEV container or on a remote server through SSH.
For projects that do not run in DDEV, the Scratchpad is a notes pad. See Notes for projects without DDEV.
Running Code
| Action | Shortcut |
|---|---|
| Run the selection. If there is no selection, run all the code | Cmd+Enter (macOS) / Ctrl+Enter |
| Run the current block (the lines between two empty lines) | Cmd+Shift+Enter / Ctrl+Shift+Enter |
| Open the history | Cmd+Shift+H / Ctrl+Shift+H |
The Scratchpad runs your code one statement at a time. When a statement fails, the run stops at that statement. The error shows in the output, and the editor marks the line.
The editor toolbar has these buttons:
- Restart PHP worker (DDEV only): starts a new PHP process. This clears your variables and loads your latest code.
- Run / Stop: during a DDEV run, Run changes to Stop.
- History: shows the recent snippets that ran successfully. You can load a snippet, or load it and run it.
Framework Variables
These variables are available:
| Framework | Available |
|---|---|
| Laravel | All helpers and facades, for example app(), DB::, User::query() |
| Symfony | $kernel, $container, and $em (the Doctrine entity manager) |
| Drupal | $container, and all static helpers, for example \Drupal::entityTypeManager() |
| WordPress | All WordPress functions, for example get_posts() |
For Symfony, the Scratchpad also loads your .env files, so the database and other services work.
Reading the Output
Above the output, a summary bar shows:
- The run time and the peak memory
- The number of database queries. Click it to see each query with its bindings and time.
- Possible N+1, when the same query runs many times with different values
- The framework version and the PHP version
Each statement that returns a value has its own card. The card shows the line number and the run time. When a statement returns a list of rows (for example an Eloquent collection, a Doctrine result, or a Drupal query result), you can see it as a Table or as a Dump. For a long list, the table shows the first rows and how many rows there are in total.
The PHP Worker (DDEV)
On DDEV, the first run starts a PHP process in your web container and boots your framework. Later runs use the same process, so they start in a few milliseconds. Variables stay available between runs. For example, you can load a model in one run and use it in the next run.
The Scratchpad starts a new worker automatically when:
- You change code in your project (for example in
app/,config/,src/, or custom Drupal modules) - A run takes longer than the time limit
- You click Stop or Restart PHP worker
Remote (SSH) runs do not use a worker. Each remote run starts a new PHP process.
PHP IntelliSense
The editor uses a PHP language server (Phpactor) that reads your project. It gives you:
- Completion for classes, methods, properties, and functions, with automatic
useimports - Hover documentation and signature help
- Error markers for code that cannot work, for example an unknown method
The status indicator at the bottom right of the editor shows the state: Downloading, Indexing project, or IntelliSense ready.
Framework Knowledge
DevWorkspace Pro reads your running application and writes helper files ("stubs") for the language server. These give completion for code that uses PHP magic:
| Framework | What completes |
|---|---|
| Laravel | Model columns with their cast types, relations, scopes, query builder chains (User::where(...)->first()->), collections, enum casts, and facades such as DB:: and Str:: |
| Symfony | Doctrine repositories and finders ($em->getRepository(Post::class)->find(1)->), Doctrine collections, and service IDs in $container->get('...') |
| Drupal | Entity fields, including bundle fields ($node->body->value, $node->field_tags->entity->getName()) |
DevWorkspace Pro updates these stubs when you open the Scratchpad and after each DDEV run, but only when your models, entities, or migrations changed. For Drupal, the stubs also update regularly, because Drupal keeps field settings in the database.
Live Completion
After a DDEV run, completion also reads the live values in the worker. When you type $user-> or $data[', the list shows the real attributes, loaded relations, and array keys of that variable, with their current values.
First Use
The first time you open the Scratchpad, DevWorkspace Pro downloads the language server and indexes your project. Indexing can take a few minutes, and depends on the size of your vendor folder. Later starts take a few seconds.
To free disk space, open Preferences → Scratchpad and click Clear cache. DevWorkspace Pro also removes old indexes to save disk space.
Settings
Open Preferences → Scratchpad:
- Scratchpad Run Time Limit (seconds): the maximum time for one run. The default is 120 seconds. When a DDEV run takes longer, the Scratchpad stops it and starts a new worker. For remote runs, the server stops the process when the
timeoutcommand is available. - IntelliSense index cache: shows the disk space that the project indexes use, and has a Clear cache button.
Files in Your Project
The Scratchpad writes files only into vendor/.devworkspacepro/ in your project. This folder is inside vendor/, so Git ignores it in a normal project.
| Path | Purpose |
|---|---|
runner-*.php, runtime-*.phar | Run your code. New versions replace old ones automatically. |
stubs/ | Helper files for PHP IntelliSense |
For remote (SSH) runs, the Scratchpad uploads the runner files to ~/.devworkspacepro/ on the server.
You can delete these folders at any time. DevWorkspace Pro writes them again when necessary.
Notes for Projects Without DDEV
For a project that does not run in DDEV, the Scratchpad tab is a notes pad. The code runner is available in DDEV projects. The toolbar shows Notes and snippets. Use the pad for notes, commands and snippets.
- Syntax highlighting: the default is Auto-detect. To set the language, select it in the list, for example Markdown, PHP, C# or SQL. Auto-detect finds C# from
usingdirectives,{ get; set; }properties andConsole.WriteLinecalls. - Each project has its own notes.
Saving
DevWorkspace Pro saves the notes to disk a short time after you stop typing. It also saves them when you leave the tab or the window. The notes stay after you restart or update DevWorkspace Pro.
The icon in the toolbar shows the state. Move the pointer over it to see the details.
| Icon | Meaning |
|---|---|
| Cloud with an arrow up | Saving notes... |
| Check | Notes saved at the time of the last save |
| Red ! | Notes not saved. Edit again to retry. |
The notes stay on your computer. When you rename the project, the notes move to the new name. When you delete the project, DevWorkspace Pro deletes its notes.
Troubleshooting
IntelliSense Shows "Unavailable" or "Stopped"
- Unavailable: your platform is not supported yet.
- Stopped: click Retry next to the status.
Completion Does Not Know My New Model or Field
Run any code once in the Scratchpad (DDEV), or open the Scratchpad tab again. This makes DevWorkspace Pro update the stubs. The project must be running for column types and Drupal fields.
Remote Execution Fails
- Make sure that the SSH private key path is correct
- Make sure that the remote project root path exists
- Make sure that PHP 7.4 or later is available on the server as
php
"Unable to start subsystem: sftp" Error
The Scratchpad uses SFTP to upload its files to the server. This error means that the SSH server does not have SFTP enabled. For the fix, see Remote SSH.