Смотрите, какую штуку нашел. Виртуальная машина и компилятор ПХП для встройки в свой Си код. Все в одном файле, как мы любим. 60 тысяч строк - как мы не любим, но что уж поделать.
А вот список встроенных функций (довольно внушительный):
Смотрите, какую штуку нашел. Виртуальная машина и компилятор ПХП для встройки в свой Си код. Все в одном файле, как мы любим. 60 тысяч строк - как мы не любим, но что уж поделать.
А вот список встроенных функций (довольно внушительный):
Из коробки для ESP32 не компилируется, но если чуть-чуть поправить, то компилируется.
Вот патчик, чтобы компилировалось.
diff -urN OLD/ph7.c NEW/ph7.c
--- OLD/ph7.c 2026-06-11 15:29:42.793868800 +0700
+++ NEW/ph7.c 2026-06-11 15:24:04.916947600 +0700
@@ -79,6 +79,7 @@
/* This file was automatically generated. Do not edit (except for compile time directive)! */
#ifndef _PH7_H_
#define _PH7_H_
+
/*
* Symisc PH7: An embeddable bytecode compiler and a virtual machine for the PHP(5) programming language.
* Copyright (C) 2011-2012, Symisc Systems http://ph7.symisc.net/
@@ -126,7 +127,11 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* $SymiscID: ph7.h v2.1 UNIX|WIN32/64 2012-09-15 09:43 stable <chm@symisc.net> $ */
+
+#define ESP32
+
#include <stdarg.h> /* needed for the definition of va_list */
+
/*
* Compile time engine version, signature, identification in the symisc source tree
* and copyright notice.
@@ -257,13 +262,14 @@
* By default we will assume that we are compiling on a UNIX systems.
* Otherwise the OS_OTHER directive must be defined.
*/
-#if !defined(OS_OTHER)
-#if !defined(__UNIXES__)
-#define __UNIXES__
-#endif /* __UNIXES__ */
-#else
-#endif /* OS_OTHER */
+# if !defined(OS_OTHER)
+# if !defined(__UNIXES__)
+# define __UNIXES__
+# endif /* __UNIXES__ */
+# else
+# endif /* OS_OTHER */
#endif /* __WINNT__/__UNIXES__ */
+
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef signed __int64 sxi64; /* 64 bits(8 bytes) signed int64 */
typedef unsigned __int64 sxu64; /* 64 bits(8 bytes) unsigned int64 */
@@ -11564,7 +11570,7 @@
}
/*
* void var_dump(expression,....)
- * var_dump РїС—Р… Dumps information about a variable
+ * var_dump пїЅ Dumps information about a variable
* Parameters
* One or more expression to dump.
* Returns
@@ -13603,9 +13609,9 @@
* and the current working directory before failing. The include()
* construct will emit a warning if it cannot find a file; this is different
* behavior from require(), which will emit a fatal error.
- * If a path is defined РїС—Р… whether absolute (starting with a drive letter
+ * If a path is defined пїЅ whether absolute (starting with a drive letter
* or \ on Windows, or / on Unix/Linux systems) or relative to the current
- * directory (starting with . or ..) РїС—Р… the include_path will be ignored altogether.
+ * directory (starting with . or ..) пїЅ the include_path will be ignored altogether.
* For example, if a filename begins with ../, the parser will look in the parent
* directory to find the requested file.
* When a file is included, the code it contains inherits the variable scope
@@ -19984,8 +19990,39 @@
#ifdef __WINNT__
#include <Windows.h>
#elif defined(__UNIXES__)
-#include <sys/utsname.h>
+# if (__has_include(<sys/utsname.h>))
+# include <sys/utsname.h>
+# else
+struct utsname {
+
+ char *sysname;
+ char *nodename;
+ char *release;
+ char *version;
+ char *machine;
+
+};
+
+static int uname(struct utsname *out) {
+
+ if (out == NULL)
+ return -1;
+
+ out->sysname = "FreeRTOS";
+ out->nodename = "local";
+ out->release = "6";
+ out->version = "7";
+#ifdef __XTENSA__
+ out->machine = "Xtensa-LX6/LX7";
+#else
+ out->machine = "RISCV";
#endif
+
+ return 0;
+}
+# endif
+#endif
+
/*
* string php_uname([ string $mode = "a" ])
* Returns information about the host operating system.
@@ -24589,7 +24626,7 @@
#include <unistd.h>
#include <sys/uio.h>
#include <sys/stat.h>
-#include <sys/mman.h>
+//#include <sys/mman.h>
#include <sys/file.h>
#include <pwd.h>
#include <grp.h>
@@ -24799,7 +24836,11 @@
{
struct stat st;
int rc;
+#ifdef ESP32
+ rc = stat(zPath,&st);
+#else
rc = lstat(zPath,&st);
+#endif
if( rc != 0 ){
return -1;
}
@@ -24980,6 +25021,8 @@
return rc == 0 ? PH7_OK : -1;
}
/* int (*xMmap)(const char *,void **,ph7_int64 *) */
+#ifdef ESP32
+#else
static int UnixVfs_Mmap(const char *zPath,void **ppMap,ph7_int64 *pSize)
{
struct stat st;
@@ -25011,6 +25054,8 @@
{
munmap(pView,(size_t)nSize);
}
+#endif
+
/* void (*xTempDir)(ph7_context *) */
static void UnixVfs_TempDir(ph7_context *pCtx)
{
@@ -25135,8 +25180,13 @@
UnixVfs_Getenv, /* int (*xGetenv)(const char *,ph7_context *) */
UnixVfs_Setenv, /* int (*xSetenv)(const char *,const char *) */
UnixVfs_Touch, /* int (*xTouch)(const char *,ph7_int64,ph7_int64) */
+#ifdef ESP32
+ 0,
+ 0,
+#else
UnixVfs_Mmap, /* int (*xMmap)(const char *,void **,ph7_int64 *) */
UnixVfs_Unmap, /* void (*xUnmap)(void *,ph7_int64); */
+#endif
UnixVfs_link, /* int (*xLink)(const char *,const char *,int) */
UnixVfs_Umask, /* int (*xUmask)(int) */
UnixVfs_TempDir, /* void (*xTempDir)(ph7_context *) */
@@ -42548,7 +42598,9 @@
#ifdef __WINNT__
#include <Windows.h>
#elif defined(__UNIXES__)
-#include <sys/utsname.h>
+# if (__has_include(<sys/utsname.h>))
+# include <sys/utsname.h>
+# endif
#endif
/*
* PHP_OS