donglan6967
2015-12-02 11:11
浏览 84
已采纳

如何自动确定项目使用哪些PHP扩展?

Is there a way to automatically find out which PHP extensions are used by a particular project you have the source code of?

When migrating a website from a one server to another, I often find myself wondering what PHP extensions should I enable for the website to function normally. Yes, this use case would probably be irrelevant if the project used Docker or had an exhaustive install guide, but it's not always the case.

I was thinking of a script that went through all of the .php files and looked for specific function calls or classes, for exeample:

  • new mysqli( or mysqli_connect(: mysqli
  • imagecreate( or imagepng or imagejpeg or ... : gd
  • curl_init( : curl

Does a similar script already exist? If not, would it make sense to write it?

图片转代码服务由CSDN问答提供 功能建议

有没有办法自动找出具有源代码的特定项目使用的PHP扩展?

将网站从一台服务器迁移到另一台服务器时,我常常想知道我应该为网站正常运行启用哪些PHP扩展。 是的,如果项目使用Docker或者有一个详尽的安装指南,这个用例可能是无关紧要的,但情况并非总是如此。

我在考虑一个遍历所有的脚本 .php文件并查找特定的函数调用或类,例如:

  • new mysqli( mysqli_connect(:mysqli
  • imagecreate( imagepng imagejpeg 或......:gd
  • curl_init(:curl

    类似的脚本是否已经存在?如果没有,编写它是否有意义 ?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongxun1244 2015-12-02 14:42
    最佳回答

    Writing as answer as requested by OP in their comment

    glenscott/php-dependencies

    Although not a complete solution, this will lessen the manual work you'll have to do: https://github.com/glenscott/php-dependencies

    A few caveats are;

    • Your source code and its dependencies must lie under one directory -- included/required files outside this directory are not scanned
    • As it stands, only function dependencies are found. This means that class dependencies are not checked.

    You can read the blog post by the author here: http://www.glenscott.co.uk/blog/finding-function-dependencies-in-your-php-applications/

    To run

    You can do these via the command line or through a web browser.

    • Step 1) Getting PHP environment details: php get-env-functions.php

    • Step 2) Find dependencies: php scan-dependencies.php

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题