php micro,PHPMicro

microphp 自执行 SAPI

micro 自执行 SAPI 提供了 php“自执行文件”的可能性

你只需要将构建的 micro.sfx 文件与任意 php 文件或者 phar 包拼接(cat 或者 copy /b)为一个文件就可以直接执行这个 php 文件

兼容性

目前兼容 PHP7.4 与 8.0;兼容 Windows、Linux、macOS。

构建

准备源码

1.将本仓库clone到php源码的sapi/micro下

# 在php源码目录下

git clone sapi/micro

2.打patch

patch文件在patches目录下,选择patch文件:

patch文件

平台/PHP版本

是否必须

作用

disable_huge_page.patch

Linux

可选

禁用linux构建的max-page-size选项,缩减sfx体积(典型的, 10M+ -> 5M)

vcruntime140_.patch

Windows

必选

禁用sfx启动时GetModuleHandle(vcruntime140(d).dll)

win32_.patch

Windows

必选

修改构建系统以静态构建

zend_stream.patch

Windows

必选

修改构建系统以静态构建

phar.patch

*

可选

实现phar的支持

并分别进行patch:

# 在php源码目录下

patch -p1 < sapi/micro/patches/

unix-like 构建

0.参考官方构建说明准备PHP构建环境

1.buildconf

# 在php源码目录下

./buildconf --force

2.configure

# 在php源码目录下

./configure

参考的选项:

--disable-phpdbg --disable-cgi --disable-cli --disable-all --enable-micro --enable-phar --with-ffi --enable-zlib

3.make

# 在php源码目录下

make micro

(make all(或者make) 或许也可以,但建议还是只构建micro SAPI

生成的文件在 sapi/micro/micro.sfx

Windows 构建

0.参考官方构建说明准备PHP构建环境

1.buildconf

# 在php源码目录下

buildconf

2.configure

# 在php源码目录下

configure

参考的选项:

--disable-all --disable-zts --enable-micro --enable-phar --with-ffi --enable-zlib

3.make 由于构建系统的实现问题, Windows下不能使用nmake命令直接构建,使用nmake sfx来构建

# 在php源码目录下

nmake sfx

生成的文件在 \\micro.sfx

使用

将micro.sfx和php文件拼接即可

例如:myawesomeapp.php内容为

echo "hello, this is my awesome app." . PHP_EOL;

linux下

cat /path/to/micro.sfx myawesomeapp.php > myawesomeapp

chmod 0755 ./myawesomeapp

./myawesomeapp

# 回显 "hello, this is my awesome app."

或者Windows下

COPY /b \path\to\micro.sfx + myawesomeapp.php myawesomeapp.exe

myawesomeapp.exe

REM 回显 "hello, this is my awesome app."

优化

linux下php对于hugepages优化导致了生成的文件很大,如果不考虑对hugepages的优化,使用disable_huge_page.patch来来减小文件尺寸

linux下静态构建需要包含c标准库,常见的glibc较大,推荐使用musl,手动安装的musl或者某些发行版会提供gcc(或clang)的musl wrapper:musl-gcc或者musl-clang。在进行configure之前,通过指定CC和CXX变量来使用这些wrapper

例如

# ./buildconf things...

export CC=musl-gcc

export CXX=musl-gcc

# ./configure balabala

# make balabala

linux下构建时一般希望是纯静态的,但构建使用的发行版不一定提供依赖的库(zlib libffi等)的静态库版本,这时考虑自行构建依赖库

以libffi为例:

# 通过git获取源码

git clone https://github.com/libffi/libffi

cd libffi

git checkout

autoreconf -i

# 或者直接下载tarball解压

wget

tar xf

cd

# 如果使用musl的话

export CC=musl-gcc

export CXX=musl-gcc

# 构建安装

./configure --prefix=/my/prefered/path &&

make -j`nproc` &&

make install

然后使用以下export命令来构建micro:

# ./buildconf things...

# export CC=musl-xxx things...

export PKG_CONFIG_PATH=/my/prefered/path/lib/pkgconfig

# ./configure balabala

# make balabala

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MicroPHP v2.3.3 更新日志: 优化了: 1.数据验证的手机号验证规则,支持17号段手机号 修复了: 1.PDO数据库驱动RND拼写错误,更正为RAND MicroPHP v2.3.2更新日志: 修复了: 1.apache伪静态支持问题,新版apache在.htaccess中开启了伪静态在之后, $_SERVER里面的PATH_INFO变量变了名字为:REDIRECT_PATH_INFO 升级提示:无   升级提示: 1.修改入口文件里面最后两行 WoniuRouter::setConfig($system); WoniuRouter::loadClass(); 修改为: MpRouter::setConfig($system); MpRouter::loadClass(); 即可。 2.如果使用了插件模式,修改插件入口文件plugin.php里面最后一行 WoniuRouter::setConfig($system); 修改为: MpRouter::setConfig($system); 即可。 3.如果自定义了loader,ver2.2.14以前是自定义了loader必须继承WoniuLoader,现在修改为继承MpLoader即可。 4.如果自己使用了WoniuRouter::setConfig($system);WoniuRouter::loadClass(); 修改为MpRouter::setConfig($system);MpRouter::loadClass();即可.   MicroPHP是一个免费、开源、敏捷的MVC模式的PHP开发框架。它易拓展而不失灵活,可以轻松对应大中小型项目。它没有大而全的功能,只给你最需要的底层功能,但是给你无限的灵活拓展能力。   说一下MicroPHP的特性: 极简核心 整个框架核心就一个文件MicroPHP.php(压缩后的文件MicroPHP.min.php,140KB左右)。 入口亦配置 一个入口文件index.php也是整个项目的配置文件,可以自定义多个入口文件达到不同项目共存的目的,项目之间随意共享类库、帮助文件等目录,框架核心文件采用零侵入式编写,整个框架运行不依赖任何外部变量。 独特插件模式 插件模式可以把框架嵌入到任何现有的程序代码到中,然后按着MicroPHP框架的各种特性写代码。 结构灵活 项目控制器、模型、视图、类库等各种文件夹完全自定义,都不是必需的,用到什么就建立什么文件夹,彻底摆脱一堆无用的一大堆文件夹的困扰。 类库懒加载 类库采用懒加载模式,只在需要时才包含类库,而不是一次全部加载,做到按需启用。且支持一级子文件夹自动加载,在类库很多需要用文件夹分类时,能保持程序结构的简洁清晰。 共享视图数据 没有视图就不能指定视图数据?文件可以include共享那么视图为什么不能共享数据呢?在MicroPHP里面你不再有这个困挠,MicroPHP可以在$this->view_vars数组里面存放你的任何想在视图里面使用的全局数据。 SESSION管理灵活 SESSION托管支持:mongodb、mysql、memcache、redis。配置灵活,根据项目具体情况择优选用即可。 缓存灵活 缓存支持:auto、apc、sqlite、files、memcached、redis、wincache、xcache、memcache。auto:自动模式。 缓存第二驱动 当你现在代码中使用的是memcached,然后代码转移到一个新服务器且不支持memcached,这时候怎么办呢?设置第二驱动即可,当你设置的驱动不支持的时候,系统就使用第二驱动。 HMVC模式 HMVC(Hierarchical-Model-View-Controller),也可以叫做 Layered MVC。顾名思义,就是按等级划分的 MVC 模式,简单的解释就是把MVC又细分成了多个子 MVC,每个模块就分成一个 MVC。使用 HMVC 的好处就是可以降低各个功能模块之间的耦合性,提高代码复用性,使得每个功能都可以独立出来,每个模块都有自己的 MVC 结构,这就有点像 ActiveX 控件,每个控件都有自己的行为,控件之间互不影响。     相关阅读 MicroPHP 2.2.12 详细发布说明 同类推荐:程序框架
PHP Microservices by Carlos Perez Sanchez English | 29 Mar. 2017 | ASIN: B01MQGB212 | 392 Pages | AZW3 | 4.91 MB Key Features Build your own applications based on event-driven microservices and set them up on a production server. Successfully transform any monolithic application into a microservice. Monitor the health of your application, prevent downtime, and reduce costs. Book Description The world is moving away from bulky, unreliable, and high-maintenance PHP applications, to small, easy-to-maintain and highly available microservices and the pressing need is for PHP developers to understand the criticalities in building effective microservices that scale at large. This book will be a reliable resource, and one that will help you to develop your skills and teach you techniques for building reliable microservices in PHP. The book begins with an introduction to the world of microservices, and quickly shows you how to set up a development environment and build a basic platform using Docker and Vagrant. You will then get into the different design aspects to be considered while building microservices in your favorite framework and you will explore topics such as testing, securing, and deploying microservices. You will also understand how to migrate a monolithic application to the microservice architecture while keeping scalability and best practices in mind. Furthermore you will get into a few important DevOps techniques that will help you progress on to more complex domains such as native cloud development, as well as some interesting design patterns. By the end of this book you will be able to develop applications based on microservices in an organized and efficient way. You will also gain the knowledge to transform any monolithic applications into microservices. What you will learn Set up a development environment using the right strategies and tools. Learn about application design and structure to start implementing your application. Transform a monolithic application into microservices. Explore the best way to start implementing your application using testing. Understand how to monitor your microservices, handle errors, and debug the application. Deploy your finished application into a production environment and learn how to solve common problems. Know how to scale your application based on microservices once it is up–and-running. About the Author Carlos Perez Sanchez is a backend web developer with more than 10 years of experience in working with the PHP language. He loves finding the best solution for every single problem on web applications and coding, looking to push forward the best practices for development, ensuring a high level of attention to detail.He has a bachelors degree in computer engineering from the University of Alicante in Spain, and he has worked for different companies in the United Kingdom and Spain. He has also worked for American companies and is currently working for Pingvalue. You can connect with him on LinkedIn at https://www.linkedin.com/in/mrcarlosdev. Pablo Solar Vilarino is a software developer who became interested in web development when PHP 4 started becoming a popular language. Over the last few years, he has worked extensively with web, cloud, and mobile technologies for medium-to-large companies and is currently an e-commerce developer at NITSNETS. He has a passion for new technologies, code standards, scalability, performance, and open source projects. Pablo can be approached online at https://pablosolar.es/. Table of Contents What are Microservices? Development Environment Application Design Testing and Quality Control Microservices Development Monitoring Security Deployment From Monolithic to Microservices Strategies for Scalability Best Practices and Conventions Cloud and DevOps
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值