You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: update extension generator doc for a more natural order (#2279)
I've been advised during Dutch PHP Conference (thanks @dseguy!) to move
the "Generate your extension" section before going deep into type
juggling. I agree: the reader will have way more satisfaction and will
be eager to dig the topic if the basic case already works.
There may be more to improve but this is a first quick-win.
Copy file name to clipboardExpand all lines: docs/extensions.md
+59-59Lines changed: 59 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,65 @@ There are two important things to note here:
80
80
- A directive comment `//export_php:function` defines the function signature in PHP. This is how the generator knows how to generate the PHP function with the right parameters and return type;
81
81
- The function must return an `unsafe.Pointer`. FrankenPHP provides an API to help you with type juggling between C and Go.
82
82
83
-
While the first point speaks for itself, the second may be harder to apprehend. Let's take a deeper dive to type juggling in the next section.
83
+
While the first point speaks for itself, the second may be harder to apprehend. Let's take a deeper dive to type juggling later in this guide.
84
+
85
+
### Generating the Extension
86
+
87
+
This is where the magic happens, and your extension can now be generated. You can run the generator with the following command:
> Don't forget to set the `GEN_STUB_SCRIPT` environment variable to the path of the `gen_stub.php` file in the PHP sources you downloaded earlier. This is the same `gen_stub.php` script mentioned in the manual implementation section.
95
+
96
+
If everything went well, your project directory should contain the following files for your extension:
97
+
98
+
-**`my_extension.go`** - Your original source file (remains unchanged)
99
+
-**`my_extension_generated.go`** - Generated file with CGO wrappers that call your functions
100
+
-**`my_extension.stub.php`** - PHP stub file for IDE autocompletion
101
+
-**`my_extension_arginfo.h`** - PHP argument information
102
+
-**`my_extension.h`** - C header file
103
+
-**`my_extension.c`** - C implementation file
104
+
-**`README.md`** - Documentation
105
+
106
+
> [!IMPORTANT]
107
+
> **Your source file (`my_extension.go`) is never modified.** The generator creates a separate `_generated.go` file containing CGO wrappers that call your original functions. This means you can safely version control your source file without worrying about generated code polluting it.
108
+
109
+
### Integrating the Generated Extension into FrankenPHP
110
+
111
+
Our extension is now ready to be compiled and integrated into FrankenPHP. To do this, refer to the FrankenPHP [compilation documentation](compile.md) to learn how to compile FrankenPHP. Add the module using the `--with` flag, pointing to the path of your module:
Note that you point to the `/build` subdirectory that was created during the generation step. However, this is not mandatory: you can also copy the generated files to your module directory and point to it directly.
124
+
125
+
### Testing Your Generated Extension
126
+
127
+
You can create a PHP file to test the functions and classes you've created. For example, create an `index.php` file with the following content:
Once you've integrated your extension into FrankenPHP as demonstrated in the previous section, you can run this test file using `./frankenphp php-server`, and you should see your extension working.
> Don't forget to set the `GEN_STUB_SCRIPT` environment variable to the path of the `gen_stub.php` file in the PHP sources you downloaded earlier. This is the same `gen_stub.php` script mentioned in the manual implementation section.
593
-
594
-
If everything went well, your project directory should contain the following files for your extension:
595
-
596
-
-**`my_extension.go`** - Your original source file (remains unchanged)
597
-
-**`my_extension_generated.go`** - Generated file with CGO wrappers that call your functions
598
-
-**`my_extension.stub.php`** - PHP stub file for IDE autocompletion
599
-
-**`my_extension_arginfo.h`** - PHP argument information
600
-
-**`my_extension.h`** - C header file
601
-
-**`my_extension.c`** - C implementation file
602
-
-**`README.md`** - Documentation
603
-
604
-
> [!IMPORTANT]
605
-
> **Your source file (`my_extension.go`) is never modified.** The generator creates a separate `_generated.go` file containing CGO wrappers that call your original functions. This means you can safely version control your source file without worrying about generated code polluting it.
606
-
607
-
### Integrating the Generated Extension into FrankenPHP
608
-
609
-
Our extension is now ready to be compiled and integrated into FrankenPHP. To do this, refer to the FrankenPHP [compilation documentation](compile.md) to learn how to compile FrankenPHP. Add the module using the `--with` flag, pointing to the path of your module:
Note that you point to the `/build` subdirectory that was created during the generation step. However, this is not mandatory: you can also copy the generated files to your module directory and point to it directly.
622
-
623
-
### Testing Your Generated Extension
624
-
625
-
You can create a PHP file to test the functions and classes you've created. For example, create an `index.php` file with the following content:
Once you've integrated your extension into FrankenPHP as demonstrated in the previous section, you can run this test file using `./frankenphp php-server`, and you should see your extension working.
640
-
641
641
## Manual Implementation
642
642
643
643
If you want to understand how extensions work or need full control over your extension, you can write them manually. This approach gives you complete control but requires more boilerplate code.
0 commit comments