vercel-php 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
vercel-php 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
vercel-php 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT License
开发语言 JavaScript
操作系统 跨平台
软件类型 开源软件
所属分类 云计算Serverless 系统
开源组织
地区 不详
投 递 者 首席测试
适用人群 未知
收录时间 2021-12-02

软件简介

PHP Runtime for Vercel

Enjoyable & powerful 🐘 PHP Runtime (php.vercel.app) for Vercel platform.

🏋️‍♀️ It works with these frameworks and tools. Discover more at examples.

Made with ❤️ by @f3l1x (f3l1x.io) • 🐦 @xf3l1x


😎 Getting Started

Let's picture you want to deploy your awesome microproject written in PHP and you don't know where. You have found Vercel it's awesome, but for static sites. Not anymore! I would like to introduce you your new best friend vercel-php, PHP runtime for Vercel platform.

Most simple example project is this one, using following project structure.

project
├── api
│   └── index.php
└── vercel.json

First file api/index.php is entrypoint of our application. It should be placed in api folder, it's very standard location for Vercel.

<?php
phpinfo();

Second file vercel.json is pure gold here. Setup your project with configuration like this and voila. That's all.

{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.4.0"
    }
  }
}

Last thing you have to do is call vercel. If you are more interested take a look at features and usage.

# Install it globally
npm i -g vercel

# Log in
vercel login

# Let's fly
vercel

Are you ready to deploy your first PHP project to Vercel? Click & Go!

🤗 Features

  • Architecture: PHP development server (🚀 fast enough)
  • PHP version: 8.0.3
  • Extensions: apcu, bcmath, brotli, bz2, calendar, Core, ctype, curl, date, dom, ds, exif, fileinfo, filter, ftp, gettext, hash, iconv, igbinary, imap, intl, json, libxml, lua, mbstring, mongodb, msgpack, mysqli, mysqlnd, openssl, pcntl, pcre, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, phalcon, Phar, protobuf, psr, readline, redis, Reflection, runkit7, session, SimpleXML, soap, sockets, sodium, SPL, sqlite3, standard, swoole, timecop, tokenizer, uuid, xml, xmlreader, xmlrpc, xmlwriter, xsl, Zend OPcache, zlib
  • Speed: cold ~250ms / warm ~5ms
  • Memory: ~90mb
  • Frameworks: Nette, Symfony, Lumen, Slim, Phalcon

List of all installable extensions is on this page https://blog.remirepo.net/pages/PECL-extensions-RPM-status.

⚙️ Usage

Before you can start using this runtime, you should learn about Vercel and how runtimes works. Take a look at blogpost about Serverless Functions.

You should define functions property in vercel.json and list PHP files directly or using wildcard (*). If you need to route everything to index, use routes property.

{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.4.0"
    }
  },
  "routes": [
    { "src": "/(.*)",  "dest": "/api/index.php" }
  ]
}

Do you have more questions ()? Let's move to FAQ.

👨‍💻 vercel dev

For running vercel dev properly, you need to have PHP installed on your computer, learn more. But it's PHP and as you know PHP has built-in development server. It works out of box.

php -S localhost:8000 api/index.php

👀 Demo

PHP

🎯Examples

Browse more examples. 👀

📜 Resources

🚧 Roadmap

Next

Done

  • next-gen PHP runtime
  • Composer
    • config.composer: true
    • composer.json detection
  • zero config
  • customize php.ini
  • vercel dev
  • typescript codebase
  • github workflows (CI)
  • PHP 7.4
  • composer.json scripts
  • PHP 8.0

Help wanted

  • create examples using vercel-php

⁉️ FAQ

1. How to use more then one endpoint (index.php)?
project
├── api
│   ├── index.php
│   ├── users.php
│   └── books.php
└── vercel.json
{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.4.0"
    },

    // Can be list also directly

    "api/index.php": {
      "runtime": "vercel-php@0.4.0"
    },
    "api/users.php": {
      "runtime": "vercel-php@0.4.0"
    },
    "api/books.php": {
      "runtime": "vercel-php@0.4.0"
    }
  }
}
2. How to route everything to index?
{
  "functions": {
    "api/index.php": {
      "runtime": "vercel-php@0.4.0"
    }
  },
  "routes": [
    { "src": "/(.*)",  "dest": "/api/index.php" }
  ]
}
3. How to update memory limit?

Additional function properties are memory, maxDuration. Learn more about functions.

{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.4.0",
      "memory": 3008,
      "maxDuration": 60
    }
  }
}
4. How to use it with Composer?

Yes, Composer is fully supported.

project
├── api
│   └── index.php
├── composer.json
└── vercel.json
{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.4.0"
    }
  }
}
{
  "require": {
    "php": "^7.4",
    "tracy/tracy": "^2.0"
  }
}

It's also good thing to create .vercelignore file and put /vendor folder to this file. It will not upload /vendor folder to Vercel platform.

5. How to override php.ini / php configuration ?

Yes, you can override php configuration. Take a look at default configuration at first. Create a new file api/php.ini and place there your configuration. Don't worry, this particulary file will be removed during building phase on Vercel.

project
├── api
│   ├── index.php
│   └── php.ini
└── vercel.json
{
  "functions": {
    "api/*.php": {
      "runtime": "vercel-php@0.4.0"
    }
  }
}
# Disable some functions
disable_functions = "exec, system"

# Update memory limit
memory_limit=1024M
6. How to exclude some files or folders ?

Runtimes support excluding some files or folders, take a look at doc.

{
  "functions": {
  "api/**/*.php": {
    "runtime": "vercel-php@0.4.0",
    "excludeFiles": "{foo/**,bar/config/*.yaml}",
  }
}

If you want to exclude files before uploading them to Vercel, use .vercelignore file.

7. How to call composer script(s) ?

Calling composer scripts during build phase on Vercel is supported via script named vercel. You can easilly call php, npm or node.

{
  "require": { ... },
  "require-dev": { ... },
  "scripts": {
    "vercel": [
      "@php -v",
      "npm -v"
    ]
  }
}

Files created during composer run vercel script can be used (require/include) in your PHP lambdas, but can't be accessed from browser (like assets). If you still want to access them, create fake assets.php lambda and require them. Example of PHP satis.

8. How to include some files of folders?

If you are looking for config.includeFiles in runtime, unfortunately you can't include extra files. All files in root folder are uploaded to Vercel, use .vercelignore to exclude them before upload.

9. How to develop locally?

I think the best way at this moment is use PHP Development Server.

php -S localhost:8000 api/index.php

👨🏻‍💻CHANGELOG

Show me CHANGELOG

🧙Contribution

  1. Clone this repository.
    • git clone git@github.com:juicyfx/vercel-php.git
  2. Install NPM dependencies
    • make install
  3. Make your changes
  4. Run TypeScript compiler
    • make build
  5. Run tests
    • make test
  6. Create a PR

📝 License

Copyright © 2019 f3l1x. This project is MIT licensed.

展开阅读全文

代码

评论

点击引领话题📣 发布并加入讨论🔥
暂无内容
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
node-semver 安全漏洞
ReDoS
npm node-semver是美国npm公司的一个库。 node-semver 7.5.2之前版本存在安全漏洞,该漏洞源于容易受到正则表达式拒绝服务(ReDoS)的攻击。
CVE-2022-25883 MPS-2022-5166
2023-12-20 19:47
Babel 插件任意代码执行漏洞漏洞【Poc公开】
不完整的黑名单
Babel 是开源的 JavaScript 编译器。 当使用依赖 path.evaluate() 或 path.evaluateTruthy()方法的插件编译攻击者可控的代码时将会执行恶意代码,以下插件受影响: 1. @babel/plugin-transform-runtime 2. @babel/preset-env(当使用 useBuiltIns 选项时) 3. 任何依赖于 @babel/helper-define-polyfill-provider 的 polyfill provider 插件,包括: babel-plugin-polyfill-corejs3、babel-plugin-polyfill-corejs2、babel-plugin-polyfill-es-shims、babel-plugin-polyfill-regenerator、babel-plugin-polyfill-custom @babel/下的其他插件不受影响, 但可能存在受影响的第三方插件。
CVE-2023-45133 MPS-avb9-j50z
2023-12-20 19:47
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
0 评论
0 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部