Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Proposal: Session Reloading #466

Closed
wants to merge 3 commits into from
Closed

Feature Proposal: Session Reloading #466

wants to merge 3 commits into from

Conversation

zachflower
Copy link

This PR adds (relatively basic) functionality to reload the current session in order to bring any new file changes without having to exit and re-launch PsySH. This is accomplished by replacing the current process with an identical one using pcntl_exec, automatically reloading files and accounting for any changes (see demonstration below).

Caveats

Because this is a relatively basic implementation of reloading, there are a few caveats that I think are important to mention (and would love any feedback or suggestions to work around them).

Stateless Reloads

While this reload method will account for any file changes, what it doesn't do is persist the current state, meaning that any methods defined prior to a reload will be forgotten.

Because of this, reload may not be the most appropriate command name, so if there are any suggestions for something that better reflects what is happening when the command is run I would love to hear them (refresh maybe?).

PCNTL Required

Because this command utilizes pcntl_exec to safely replace the current process with a new one, PCNTL is required. While this isn't necessarily a complication (it is a recommend extension, after all), there doesn't seem to be an established convention for commands that rely on optional dependencies.

I would love any thoughts on how to best handle this. As it stands, the current implementation puts a note in the command help text, and throws an exception on execution if pcntl_exec isn't available, however disabling the command altogether when it isn't available might be more desirable.

Demonstration

kapture 2018-01-24 at 14 29 55

Relevant Issues:

@bobthecow
Copy link
Owner

you'll be happy/sad to note that:

  1. the next release includes live code reloading! including replacing the underlying class of a current object, on the fly, without losing the object itself! it's absolutely incredible!
  2. but it doesn't work on PHP 7 :(

i've thought a lot about this. i've even considered a very similar approach to this :)

unfortunately this kind of approach has got a lot of caveats, and ultimately doesn't even "reload", as you've pointed out. i've always figured ctrl+d -> up -> enter wasn't any slower than a command, and it actually gives you a fresh start.

@zachflower
Copy link
Author

Oh snap, definitely mixed feelings! Sad not to have been able to contribute, but delighted that there's something coming down the pike (hopefully something with PHP 7 support coming shortly after) 😄

I will go ahead and close this PR then.

Unrelated: You are one of the most respectful and communicative maintainers I've seen in open source. Just thought I'd say thank you and keep being awesome 🤘

@zachflower zachflower closed this Jan 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants