通过PHP脚本下载作曲家 [英] Downloading composer via PHP script

查看:91
本文介绍了通过PHP脚本下载作曲家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php脚本,可以下载composer.phar。

I have a php script which downloads the composer.phar.

下载后,我运行 exec()安装软件包。

After it has downloaded I run exec() to install the packages.

文件夹结构为

--ROOT
  --public
--composer.josn

但是,何时我运行

exec('php composer.phar install -d'。dirname(__ DIR__),$ out,$ return);

我得到以下输出:

array(5) {
  [0]=>
  string(39) "All settings correct for using Composer"
  [1]=>
  string(14) "Downloading..."
  [2]=>
  string(0) ""
  [3]=>
  string(80) "Composer successfully installed to: /var/www/projects/funny/public/composer.phar"
  [4]=>
  string(25) "Use it: php composer.phar"
}

并且没有安装供应商软件包。

And the vendor packages aren't installed.

请明确。 phar 归档文件目前已经下载,因此现在要下载什么?运行此命令后,下载的phar的大小也从200k变为900k。

Just to be clear. The phar archive has already been downloaded at this point so what is it downloading now? Also the size of the downloaded phar goes from 200k to 900k after this command is ran.

此处提供了完整的代码,用于下载和安装:

Heres the full code to download and install:

$composer_path = __DIR__ . '/composer.phar';

$ch = curl_init();
$fh = fopen($composer_path, 'x');
curl_setopt_array($ch, array(
    CURLOPT_URL => 'https://getcomposer.org/installer',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_FILE => $fh
));
$output = curl_exec($ch);
curl_close($ch);
fclose($fh);

exec('php composer.phar install -d ' . dirname(__DIR__), $out, $return);

上面的代码是从 public

推荐答案



这里有完整的代码供下载和安装:

Heres the full code to download and install:


该代码确实下载了Composer INSTALLER,但没有下载Composer本身!如果运行该下载,则将执行安装程序,该安装程序将尝试下载Composer。您不能使用安装程序下载Composer依赖项。

That code does download the Composer INSTALLER, but NOT Composer itself! If you run that download, you execute the installer, which tries to download Composer. You cannot use the installer to download the Composer dependencies.

这篇关于通过PHP脚本下载作曲家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆