rfc:zend-vm-pause-api

PHP RFC: Zend VM Pause API

This RPC has been obsolete. Please see https://github.com/php/php-src/pull/2902 for more detail.

Introduction

There is no API for change the Zend VM's execute flow. The only approach to change the Zend VM's execute flow is introducing a new keyword and making a new opline, and use ZEND_VM_RETURN/ZEND_VM_CONTINUE macro in its handler.

So it is impossible to change the Zend VM's execute flow in an zend extension. As a result, any feature, like Fiber, related to Zend VM's execute flow cannot be implemented by a standalone extension.

Proposal

This PRFC propose a new vm_interrupt type, by which some zend extension could make the zend vm execution pause and return. So we can implement feature like Fiber in a standalone extension.

diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 183072033607..bd7408e824fc 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -8893,13 +8893,19 @@ ZEND_VM_DEFINE_OP(137, ZEND_OP_DATA);
 
 ZEND_VM_HELPER(zend_interrupt_helper, ANY, ANY)
 {
+	int8_t interrupt_type = EG(vm_interrupt);
+
 	EG(vm_interrupt) = 0;
 	if (EG(timed_out)) {
 		zend_timeout(0);
 	} else if (zend_interrupt_function) {
 		SAVE_OPLINE();
 		zend_interrupt_function(execute_data);
-		ZEND_VM_ENTER();
+		if (UNEXPECTED(interrupt_type == 2)) {
+			ZEND_VM_RETURN();
+		} else {
+			ZEND_VM_ENTER();
+		}
 	}
 	ZEND_VM_CONTINUE();
 }

Backward Incompatible Changes

None

Proposed PHP Version(s)

PHP 7.3

But I would like this patch could be backported to PHP 7.1 and PHP 7.2.

RFC Impact

None

To SAPIs

None

To Existing Extensions

None

To Opcache

None

New Constants

None

php.ini Defaults

None

Open Issues

Make sure there are no open issues when the vote starts!

Unaffected PHP Functionality

List existing areas/features of PHP that will not be changed by the RFC.

This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.

Future Scope

This sections details areas where the feature might be improved in future, but that are not currently proposed in this RFC.

Proposed Voting Choices

50%+1

Patches and Tests

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature
  4. a link to the language specification section (if any)

References

Links to external references, discussions or RFCs

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/zend-vm-pause-api.txt · Last modified: 2017/11/21 10:56 by lvht