php / php/php-src

Observer API: Correlated observer callbacks for a single invocation

Offen
#20,510 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Feature Status: Needs Triage
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

Description

Note:

I’ve already asked and explained part of this in another issue , but this is a broader feature request with example use cases.

Brief:

Observer API replacing zend_execute_ex hook provides notable benefits and one caveat (as it seems to me): there is no stable, per-invocation identifier that can be seen consistently across all observer callbacks.
Observer API callbacks are much like event handlers fired at the certain point of the lifecycle of an invocation, but they do not provide a means of identification of the invocation.
By being able to identify the invocation, information gathered in different events can be easily linked together for a meaningful “observation”.

Request:

  1. Adding a temporary to zend_execute_data (like op_array.reserved[] but per invocation) to be used for identification as developer sees fit
  2. Passing zend_execute_data (or the temporary at least) to other callbacks like zend_observer_error_cb

Use case examples:

  1. Associating runtime metrics like start time, end time, return value, exceptions together without having to retain them in memory until all infos are gathered.
  2. Associating infos gathered by means other than Observer API (e.g. hooking specific PDO functions, replacing other zif_handler handlers) with infos from callbacks.

It’s true that some of the infos named in 1st example can be easily linked together by a simple stack structure or HashTable (as pointed out in the above linked issue) but some others require more complex rules AFAICT and unnecessary bookkeeping.
zend_execute_data is already per-invocation, so I think it is cleaner and more straightforward to use that instead of each extension building and maintaining its own mapping.

P.S.: Please forgive me if there’s anything wrong with my thinking or writing; I’m not that experienced.


Cc: @bwoebi @ndossche

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die im Issue genannten Einstiegspunkte der Observer API zu lesen: zend_execute_ex, zend_observer_error_cb und zend_execute_data sowie die Verwendung von op_array.reserved[] und zif_handler. Vergleiche die zugehörige Diskussion in Issue 20336. Erledigt ist die Arbeit, wenn das Design für die Aufrufkorrelation und die Anforderungen an die Callback-Daten vereinbart und mit geeigneter Testabdeckung implementiert sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, php
Bereich
backend-api-design, compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.