Tinkerwell 4 is out now! Get the most popular PHP Scratchpad application. Learn more

Go back to Blog

Tinker with your apps in production

Marcel Pociot

I recently listened to latest episode of the Laravel Podcast, where Matt Stauffer talked with Nuno Maduro about php artisan tinker and all things CLI.

In the podcast, they said that they use tinker most for running code on production servers. And that's also a huge part of my daily workflow with Tinkerwell.

Now this might sound scary to you at first - because running any PHP code in production, sounds like a bad idea, right? But let me show you why this is super useful, and how you can do it with Tinkerwell.

Let's make it live!

So first of all - why would you want to run any PHP code against a deployed application? There are a lot of good reasons for this, so here are my most common use cases when I use Tinkerwell on production servers via SSH.

  1. Customer Support

Every now and then, there are certain situations where a user does not receive a password reset email, a payment receipt or similar. In these situations I sometimes manually reset the users password, send him an email and he can log in again.

This does not happen often enough to build an actual UI for this, so doing it with PHP is just a lot faster. So I can just connect to the app via SSH and run:

$user = User::where('email', '[email protected]')->first();

$user->password = bcrypt('your-new-secure-password');

$user->save();

And that's it. Nothing easier than that.

  1. Inspecting models

I often use Tinkerwell to perform Eloquent queries against my live database. Instead of having to write ugly SQL code, I can make use of my existing Laravel Eloquent model relations and scopes:

User::whereHas("courses", function ($query) {
    $query->where("title", "Desktop Apps with Electron");
})->count();
  1. Dispatching jobs

Sometimes it's useful to be able to dispatch a job on your production servers. For example, you might want to resend an invoice email from your live server. Again, this probably does not happen often enough to build a user interface for this, so being able to make use of Laravel's queue feature is way easier:

$order = Order::find(12345);

dispatch(new InvoiceEmail($order));

How does it work in Tinkerwell

Tinkerwell makes running your PHP code in production super easy. First, you have to setup the server that you want Tinkerwell to connect to, by clicking the "Wifi" icon in the navigation bar.

By clicking "Connect", Tinkerwell will connect to your remote server securely via SSH and you can run any code - just like you would do it locally.

It's quite important to note, that this does not modify your live app code in any way. Tinkerwell just silently connects to your server and allows you to run code within your app, but no files in your application get modified by Tinkerwell itself.

And that's about it. I think making use of Tinkerwell on live servers is one of the greatest features of the application. Do you have other use cases for Tinkerwell on your live servers? Let us know them!

Tinkerwell: The PHP Scratchpad

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.