-
Notifications
You must be signed in to change notification settings - Fork 322
Description
if (this.cliCalled) {
throw new Error(
'php.cli() can only be called once. The method sets a C-level global state that does not allow repeated calls.'
);
}
if (this.runStreamCalled) {
throw new Error(
'php.cli() can only be called if php.runStream() was not called before. The two methods set a conflicting ' +
'C-level global state.'
);
}
PR #2281 added php.cliCalled
and php.runStreamCalled
flags to prevent calling the mutually incompatible cli()
and run()
methods on the same PHP instance.
My intuition feels cautious about keeping these kinds of binary usage flags, and I am trying to determine why.
Instead of tracking whether an instance was used in a way that may conflict, would there be any benefit to explicitly modeling the relationship that callers may have with a PHP instance? Specifically, if calling cli() renders a PHP instance unusable for further requests, what if there is no cli() instance method but rather a standalone function or static method for one-time CLI execution?
Then AFAICT there would be no possibility of callers doing conflicting things with a PHP instance.
I've replied:
I like that direction! I'm trying to think of a specific way of using such an API, e.g. nothing prevents me from doing something like cli(php, args); php.run();. I wonder if we could handle it at a level higher than the PHP instance, e.g. with a method such as acquireForCLI() where reap() would destroy the php instance instead of allowing the system to recycle it.
One other thought I had was having a separate class PHPCLI that only has a .cli() method. That would complicate the types across workers, though.
Perhaps the best solution would be to just rotate the PHP runtime within the PHP class every time we call .cli().