profile-command icon indicating copy to clipboard operation
profile-command copied to clipboard

POC: Intermediate hook profiling on PHP7

Open pcfreak30 opened this issue 5 years ago • 4 comments

I believe I have created a solution for the tick profiling issue in PHP7.

The core problem I have found with the stream wrappers is you cannot actually change the length of the stream without it crashing, even with "stream filters".

So the workaround is to create a new file beside the original with a suffix, only if it has a PHP opening tag, then use that as the file resource.

Lastly, a shutdown callback is added to clean up the file, and the suffix is removed before rendering the traces.

This is not stored elsewhere as __DIR__ and __FILE__ will get changed, potentially breaking location-aware scripts.

Testing this so far seems promising. I don't consider this production-ready, so no unit tests or anything, but providing it as a foundational point to get this working again.

Thanks :)

pcfreak30 avatar Apr 25 '20 19:04 pcfreak30

Thanks for the PR, @pcfreak30 !

I do fear that such a custom stream wrapper might interfere with some hosting solutions, so we'll have to get feedback first. I think that some hosting providers use custom stream wrappers to move the filesystem from the web server serving the site to a separate NAS or similar.

I'll ask in #hosting-community channel on MakeWP Slack to see if I get some feedback on this.

schlessera avatar May 06 '20 04:05 schlessera

Link to Slack discussion: https://wordpress.slack.com/archives/C3D6T7F8Q/p1588739563086800

schlessera avatar May 06 '20 04:05 schlessera

New RFC to watch: https://wiki.php.net/rfc/deprecate_ticks

I recently worked on trying to make this PR production-ready, in the hopes of having intermediate hook profiling working again and then bundling this command. If the above RFC passes, however, this will be the death blow to intermediate hooks profiling. Until then, I don't see a point in investing more time into this, and once the RFC is passed (which I expect is going to happen eventually), I'll rip out all traces of intermediate hooks profiling and bundle the command without it.

schlessera avatar May 20 '21 18:05 schlessera

New RFC to watch: https://wiki.php.net/rfc/deprecate_ticks

I recently worked on trying to make this PR production-ready, in the hopes of having intermediate hook profiling working again and then bundling this command. If the above RFC passes, however, this will be the death blow to intermediate hooks profiling. Until then, I don't see a point in investing more time into this, and once the RFC is passed (which I expect is going to happen eventually), I'll rip out all traces of intermediate hooks profiling and bundle the command without it.

It seems that the RFC is withdrawn so there is still hope for intermediate hook profiling I assume? 🙏

cheey2003 avatar Aug 07 '21 07:08 cheey2003

Proceeding with https://github.com/wp-cli/wp-cli/issues/5594 for this repository. I've captured this PR to https://gist.github.com/danielbachhuber/6bc4276ce559ddaa8b809a17c5ad6cd5 in case this PR is auto-closed or broken in some way.

danielbachhuber avatar Nov 18 '22 15:11 danielbachhuber