-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Swoole AI Assistant] translate to fr
- Loading branch information
Showing
26 changed files
with
1,427 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"latest_commit":"7b8f0a2661a6722523970c5d0c471d162211b233"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Texte en français | ||
|
||
## Documents chinois | ||
|
||
### [Appeler un module Python dans PHP](php/tutorial.md) | ||
|
||
### [Appeler une fonction PHP dans Python](python/tutorial.md) | ||
|
||
### [Plan de développement](roadmap.md) | ||
|
||
## Extensions PHP | ||
|
||
* [Compilation et installation](php/build.md) | ||
* [Nucléus de la langue](php/core.md) | ||
* [Types intégrés](php/object.md) | ||
* [Gestion des exceptions](php/exception.md) | ||
* [Nombres entiers](php/int.md) | ||
* [Fonctions de rappel](php/fn.md) | ||
* [Copie de mémoire](php/memory.md) | ||
* [Tests de performance](benchmark.md) | ||
* [Suggestions IDE](php/composer.md) | ||
* [API Sockets](php/socket.md) | ||
* [Héritage de classes Python](php/inherit.md) | ||
|
||
## Modules Python | ||
|
||
### [Liste des fonctions](python/function.md) | ||
|
||
### [Opérations sur les objets](python/object.md) | ||
|
||
### [Opérations sur les chaînes](python/string.md) | ||
|
||
### [Opérations sur les tableaux](python/array.md) | ||
|
||
### [Opérations sur les classes](python/class.md) | ||
|
||
### [Types de référence](python/reference.md) | ||
|
||
### [Copie de mémoire](php/memory.md) | ||
* [Module d'encapsulation](python/module.md) | ||
|
||
## Tutoriels | ||
|
||
### [phpy : bibliothèque d'appel mutuel entre PHP et Python, introduisant l'écosystème Python dans PHP](https://zhuanlan.zhihu.com/p/670373512) | ||
|
||
### [Compilation et installation de phpy sous Ubuntu 18.04 avec PHP-8.3](https://mp.weixin.qq.com/s/q_-keG3clvs7Hii-oEW3RQ) | ||
|
||
### [phpy : connecter PHP à l'écosystème Python](https://zhuanlan.zhihu.com/p/671645003) | ||
|
||
### [Comment PHP appelle-t-il la plateforme de modèles open-source Magic Tower ModelScope via phpy](https://mp.weixin.qq.com/s/p5x2XwJgPpodZI_Woa8qPA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Test de charge | ||
Un script de test de charge a créé un `PyDict`, écrivant et lisant des codes `PHP` et `Python` pour exécuter `10 millions` d'opérations. | ||
|
||
- `Version PHP` : `PHP 8.2.3 (cli) (built: Mar 17 2023 15:06:57) (NTS)` | ||
|
||
- `Version Python` : `Python 3.11.5` | ||
|
||
- Système d'exploitation : `Ubuntu 20.04` | ||
- `Version GCC` : `gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)` | ||
|
||
> Veuillez noter que ce test nécessite la construction d'un `HashTable` de `10 millions` d'éléments, nécessitant au moins `2 Go` de mémoire pour fonctionner | ||
## PHP | ||
|
||
```php | ||
<?php | ||
|
||
$dict = new PyDict(); | ||
const COUNT = 10000000; | ||
|
||
$n = COUNT; | ||
$s = microtime(true); | ||
while ($n--) { | ||
$dict['key-' . $n] = $n * 3; | ||
} | ||
echo 'dict set: ' . round(microtime(true) - $s, 6) . ' secondes' . PHP_EOL; | ||
|
||
$c = 0; | ||
$n = COUNT; | ||
$s = microtime(true); | ||
while ($n--) { | ||
$c += $dict['key-' . $n]; | ||
} | ||
echo 'dict get: ' . round(microtime(true) - $s, 6) . ' secondes' . PHP_EOL; | ||
``` | ||
|
||
## Python | ||
```python | ||
import time | ||
|
||
my_dict = {} | ||
COUNT = 10000000 | ||
|
||
n = COUNT | ||
start_time = time.time() | ||
|
||
for i in range(n): | ||
my_dict["key-" + str(i)] = i * 3 | ||
|
||
elapsed_time = time.time() - start_time | ||
|
||
print(f"dict set: {elapsed_time:.6f} seconds") | ||
|
||
n = COUNT | ||
|
||
total = 0 | ||
start_time_get = time.time() | ||
for i in range(n): | ||
total += my_dict["key-" + str(i)] | ||
|
||
elapsed_time_get = time.time() - start_time_get | ||
|
||
print(f"dict get: {elapsed_time_get:.6f} seconds") | ||
``` | ||
|
||
## PHP Array | ||
```php | ||
<?php | ||
|
||
ini_set('memory_limit', '2G'); | ||
$dict = []; | ||
const COUNT = 10000000; | ||
|
||
$n = COUNT; | ||
$s = microtime(true); | ||
while ($n--) { | ||
$dict['key-' . $n] = $n * 3; | ||
} | ||
echo 'array set: ' . round(microtime(true) - $s, 6) . ' secondes' . PHP_EOL; | ||
|
||
$c = 0; | ||
$n = COUNT; | ||
$s = microtime(true); | ||
while ($n--) { | ||
$c += $dict['key-' . $n]; | ||
} | ||
echo 'array get: ' . round(microtime(true) - $s, 6) . ' secondes' . PHP_EOL; | ||
``` | ||
|
||
## Résultats comparatifs | ||
|
||
```shell | ||
(base) htf@swoole-12:~/workspace/python-php/docs/benchmark$ php dict.php | ||
dict set: 4.663758 seconds | ||
dict get: 3.980076 seconds | ||
(base) htf@swoole-12:~/workspace/python-php/docs/benchmark$ php array.php | ||
array set: 1.578963 seconds | ||
array get: 0.831129 seconds | ||
(base) htf@swoole-12:~/workspace/python-php/docs/benchmark$ python dict.py | ||
dict set: 5.321664 seconds | ||
dict get: 4.969081 seconds | ||
(base) htf@swoole-12:~/workspace/python-php/docs/benchmark$ | ||
``` | ||
|
||
En utilisant le test Python comme référence : | ||
|
||
| Nom du script | Set | Get | | ||
|:----------|:----:|-----:| | ||
| dict.php | 114% | 125% | | ||
| array.php | 337% | 599% | | ||
|
||
- `phpy` écrit dans `PyDict` avec du code PHP avec une performance `14%` supérieure à celle du Python原生, et une performance de lecture `25%` supérieure. | ||
- L'écriture dans `PHP Array` est `237%` plus rapide que l'écriture dans `Python Dict`, et la lecture est presque `500%` plus rapide. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Compilation sous Windows | ||
|
||
> Seule la version `PHP-8.1` ou supérieure est prise en charge. | ||
## Environnement de développement PHP | ||
|
||
Référence : [https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2](https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2) | ||
|
||
- Installez `Visual C++ 16.0`, adresse : [https://aka.ms/vs/16/release/vs_buildtools.exe](https://aka.ms/vs/16/release/vs_buildtools.exe) | ||
|
||
- Installez `php-sdk-binary-tools`, adresse : [https://github.com/php/php-sdk-binary-tools](https://github.com/php/php-sdk-binary-tools) | ||
|
||
- Téléchargez le code source `PHP` | ||
|
||
- Installez les bibliothèques dépendantes, adresse : [https://windows.php.net/downloads/php-sdk/deps/](https://windows.php.net/downloads/php-sdk/deps/) | ||
|
||
> Tous les fichiers liés à `PHP` sont installés dans le répertoire `d:\workspace`. | ||
## Environnement de développement Python | ||
|
||
- Installez `Python`, adresse : [https://www.python.org/downloads/windows/](https://www.python.org/downloads/windows/) | ||
|
||
- Ajoutez `d:\python` à la liste des variables d'environnement `Path`, exécutez `Python -V` dans la `console Windows`. | ||
|
||
- Ajoutez une variable d'environnement `PYTHONHOME` qui pointe vers `d:\python`. | ||
|
||
> `Python` est installé dans le répertoire `d:\python`. | ||
```shell | ||
C:\WINDOWS\system32>python -V | ||
Python 3.12.1 | ||
|
||
echo %Path% | ||
echo %PYTHONHOME% | ||
``` | ||
|
||
## Répertoire de construction | ||
|
||
```shell | ||
cd D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0 | ||
phpsdk-vs16-x64.bat | ||
``` | ||
|
||
Après succès, entrez dans le répertoire `php-src` dans ce terminal | ||
|
||
```shell | ||
cd D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0\phpdev\vs16\x64\php-8.1.5 | ||
phpsdk_deps -u | ||
``` | ||
|
||
Les projets d'extension sont placés dans le répertoire `ext` de `php-src`, par exemple : `D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0\phpdev\vs16\x64\php-8.1.5\ext\phpy`, ou vous pouvez utiliser la commande `mklink` pour créer un lien symbolique. | ||
|
||
## Configuration de la compilation | ||
|
||
```shell | ||
$ buildconf --force | ||
Rebuilding configure.js | ||
Maintenant, exécutez 'configure --help' | ||
configure --with-openssl --with-mysqlnd --with-mysqli --enable-mbstring --enable-pdo --with-pdo-mysql --with-curl --enable-cli --enable-opcache --disable-zts --enable-phpy=shared | ||
``` | ||
|
||
`--enable-phpy=shared` signifie activer l'extension `phpy` et la compiler en bibliothèque dynamique `.dll`. | ||
|
||
Après l'exécution réussie, la sortie sera : | ||
|
||
```shell | ||
... | ||
|
||
Génération de main/config.w32.h | ||
Génération de phpize | ||
Finie. | ||
|
||
|
||
Extensions activées : | ||
----------------------- | ||
| Extension | Mode | | ||
----------------------- | ||
| date | static | | ||
| hash | static | | ||
| json | static | | ||
| pcre | static | | ||
| phpy | shared | | ||
| reflection | static | | ||
| spl | static | | ||
| standard | static | | ||
----------------------- | ||
|
||
|
||
SAPI activé : | ||
------------- | ||
| Nom du Sapi | | ||
------------- | ||
| cli | | ||
------------- | ||
|
||
|
||
--------------------------------------- | ||
| | | | ||
--------------------------------------- | ||
| Type de build | Release | | ||
| Sécurité des threads | Non | | ||
| Compilateur | Visual C++ 2019 | | ||
| Architecture | x64 | | ||
| Optimisation | Désactivée PGO | | ||
| Intrinsèques natives | SSE2 | | ||
| Analyseur statique | Désactivé | | ||
--------------------------------------- | ||
|
||
|
||
Type 'nmake' pour construire PHP | ||
|
||
D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0\phpdev\vs16\x64\php-8.1.5 | ||
$ | ||
``` | ||
|
||
## Compilation des extensions | ||
```shell | ||
nmake clean | ||
nmake | ||
``` | ||
|
||
## Emballage binaire | ||
|
||
```shell | ||
nmake snap | ||
``` | ||
|
||
Après succès, un fichier `php-8.1.5-nts-Win32-vs16-x64.zip` sera généré dans `D:\workspace\php-sdk\php-sdk-binary-tools-2.2.0\phpdev\vs16\x64\php-8.1.5\x64\Release`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Compilation pour Linux/macOS/Unix | ||
|
||
> Actuellement, seule la version `Python 3.10` ou supérieure est prise en charge. | ||
- Modifiez `config.m4` pour configurer le chemin de `Python`, par défaut : `/opt/anaconda3` | ||
|
||
```shell | ||
phpize | ||
./configure | ||
make install | ||
``` | ||
|
||
Modifiez `php.ini` pour ajouter `extension=phpy.so` | ||
|
||
Utilisez `php -m` pour vérifier si elle apparaît dans la liste, utilisez `php --ri phpy` pour voir les informations, utilisez `php --re phpy` pour voir les classes et méthodes définies dans l'extension. | ||
|
||
```shell | ||
php -m | ||
---- | ||
``` | ||
php -m | ||
[Modules PHP] | ||
bcmath | ||
bz2 | ||
Core | ||
... | ||
phpy | ||
... | ||
|
||
[Modules Zend] | ||
Zend OPcache | ||
``` | ||
Paramètres de compilation | ||
---- | ||
### `--with-python-dir` | ||
Spécifiez le chemin d'installation de `Python`, par exemple `/usr/bin/python` devrait être configuré en `--with-python-dir=/usr`. | ||
Si vous utilisez `conda` pour installer `Python`, il devrait être configuré en `/opt/anaconda3`. | ||
### `--with-python-version` | ||
Spécifiez la version de `Python`, par exemple `3.10`, `3.11`, `3.12`, la version par défaut sera obtenue en utilisant `$python-dir/bin/python -V`. | ||
### `--with-python-config` | ||
Configurez le chemin de l'exécutable `python-config`, cette option a un niveau de priorité supérieur à `--with-python-dir` et `--with-python-version`. | ||
```shell | ||
(base) htf@swoole-12:~/workspace/python-php$ which python3.11-config | ||
/opt/anaconda3/bin/python3.11-config | ||
(base) htf@swoole-12:~/workspace/python-php$ python3.11-config | ||
Usage: /opt/anaconda3/bin/python3.11-config --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed | ||
(base) htf@swoole-12:~/workspace/python-php$ ./configure --wi | ||
--with-gnu-ld --with-libdir= --without-PACKAGE --with-PACKAGE --with-php-config= --with-pic --with-python-config --with-python-dir --with-python-version --with-tags= | ||
(base) htf@swoole-12:~/workspace/python-php$ ./configure --with-python-config=python3.11-config | ||
checking for grep that handles long lines and -e... /bin/grep | ||
checking for egrep... /bin/grep -E | ||
checking for a sed that does not truncate output... /bin/sed | ||
checking for pkg-config... /usr/bin/pkg-config | ||
checking pkg-config is at least version 0.9.0... yes | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Suggestions automatiques de l'IDE | ||
|
||
`phpy` offre un outil de génération automatique qui peut créer des fichiers de suggestions automatiques pour les IDE. Pour l'utiliser : | ||
|
||
```shell | ||
cd phpy/tools | ||
php gen-lib.php [nom du paquet Python] | ||
``` | ||
|
||
Par exemple pour `matplotlib.pyplot` : | ||
|
||
- Importer directement : `PyCore::import('matplotlib.pyplot')` | ||
- Génerer le fichier de suggestions : `php tools/gen-lib.php matplotlib.pyplot` | ||
|
||
Vous pouvez également configurer `tools/gen-all-lib.php` pour générer des fichiers de suggestions pour plusieurs paquets en une seule fois. | ||
|
||
## Comment l'utiliser | ||
|
||
### Installer les dépendances | ||
|
||
```shell | ||
composer require swoole/phpy | ||
``` | ||
|
||
### Utiliser le suggesteur automatique | ||
|
||
```php | ||
require dirname(__DIR__, 2) . '/vendor/autoload.php'; | ||
$plt = python\matplotlib\pyplot::import(); | ||
|
||
$x = new PyList([1, 2, 3, 4]); | ||
$y = new PyList([30, 20, 50, 60]); | ||
$plt->plot($x, $y); | ||
$plt->show(); | ||
``` | ||
|
||
![Suggérences automatiques de l'IDE](../../images/autocomplete.png) |
Oops, something went wrong.