您的位置 首页 php

php扩展管理工具composer的坑、常见问题和解决方法

php扩展管理工具composer的坑、常见问题和解决方法

composer是个好东西,正如他的中文意思,”作曲家“,但一些坑点不知道的话,就不美好了。

如果还有不知道compoesr的同学,请面壁思过5分钟。然后可以搜索到底干啥的。

我自己的理解和10年前或者15年前比。目的就是去除过多的include或者require.

必备背景知识:composer、laravel、shell

简单说明

Composer是 PHP 用来管理依赖(dependency)关系的工具。你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的库文件。

基本操作

网上的教程一搜一大把

 composer install 安装依赖包
composer update 更新依赖包
composer remove 卸载依赖包  

全局参数来一波

全局参数

下列参数可与每一个命令结合使用:

  • –verbose (-v): 增加反馈信息的详细度。
  • -v 表示正常输出。
  • -vv 表示更详细的输出。
  • -vvv 则是为了 debug。
  • –help (-h): 显示帮助信息。
  • –quiet (-q): 禁止输出任何信息。
  • –no-interaction (-n): 不要询问任何交互问题。
  • –working-dir (-d): 如果指定的话,使用给定的目录作为工作目录。
  • –profile: 显示时间和内存使用信息。
  • –ansi: 强制 ANSI 输出。
  • –no-ansi: 关闭 ANSI 输出。
  • –version (-V): 显示当前应用程序的版本信息。

需要注意的问题【坑点列表】

我以下载laravel为例

1、==== 卡着不动====

你以为它死了,其实它没死,坑你没商量。

因为某些特殊情况,老外的源特别慢,我们就得把源改为国内的。阿里某个云。

 
[root@zjt-ecs-1 composertest1]# composer install 
Do not run Composer as root/super user! See  for details
Loading composer repositories with package information
上面提示,别用root运行,我就用root运行咋了。哈哈

Warning from  You are using an outdated version of Composer. Composer 2.0 is about to be released and the older 1.x releases will self-update directly to it once it is released. To avoid surprises update now to the latest 1.x version which will prompt you before self-updating to 2.x.
Updating dependencies (including require-dev)
  

果断设置

   composer config -g repo.packagist composer   

你以为这样就飞速了。但程序运行到什么状态了并不知道。第二个必须设置的。

2、==== 添加-vvv选项 ====

这样就知道compose这个家伙到底啥情况了。

php扩展管理工具composer的坑、常见问题和解决方法

3、==== 内存不够 ====

 Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52  

Allowed memory size of xxxx

因为在php.ini设置了内存限制,但这个家伙需要更多的内存,才能把扩展列表加载到内存中。

可通过以下命令查看内存设置

 # php -r "echo ini_get('memory_limit').PHP_EOL;"  

其实看不看也没啥用,看了也还是不行,得改下。哈哈。

两个解决方法:

1)临时设置php.ini 里面的 memory_limit 为更大的值。更新完再设置为原样。

找不到php.ini的同学 在命令行里面

 #php -i | grep 'php.ini'       

2)直接命令行通过参数修改

 [root@zjt-ecs-1 composertest1]# php -d memory_limit=-1  composer install -vvv
Could not open input file: composer  

你以为行了,其实还不行,composer需要绝对路径

 [root@zjt-ecs-1 composertest1]# whereis composer
composer: /usr/bin/composer.phar /usr/bin/composer /usr/local/bin/composer  

这样就可以运行了。

 [root@zjt-ecs-1 composertest1]# php -d memory_limit=-1  /usr/bin/composer install -vvv  
php扩展管理工具composer的坑、常见问题和解决方法

一个怎么把dev的包也搞到服务器上了。接着设置。

3、==== 不安装多余的dev包 ====

 # php -d memory_limit=-1  /usr/bin/composer --no-dev install -vvv  

4、 ==== 不更新多余的dev包 ====

Updating dependencies (including require-dev) 说明开始更新dev依赖了。

 [root@zjt-ecs-1 composertest1]# composer update 
Do not run Composer as root/super user! See  for details
Loading composer repositories with package information
Warning from  You are using an outdated version of Composer. Composer 2.0 is about to be released and the older 1.x releases will self-update directly to it once it is released. To avoid surprises update now to the latest 1.x version which will prompt you before self-updating to 2.x.
Updating dependencies (including require-dev)
^C
  

5、 ==== dev 依赖的包,不安装也对php版本有要求 ====

情况是这样的。composer示例

 "mockery/mockery  

虽然用 –no-dev参数可以不安装 require-dev的包,但安装还是会检查版本的。

我服务器的php PHP 7.2.26

走你。

 composer  install --no-dev --prefer-dist -vvv  

就会得到下面的错误

 Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for mockery/mockery 1.4.1 -> satisfiable by mockery/mockery[1.4.1].
    - mockery/mockery 1.4.1 requires php ^7.3 || ^8.0 -> your PHP version (7.2.26) does not satisfy that requirement.

Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.
  

晕死[衰],不是–no-dev不是不安装dev的包吗?

结果网上搜索显示,这个家伙有bug.[流泪]

php扩展管理工具composer的坑、常见问题和解决方法

php扩展管理工具composer的坑、常见问题和解决方法

我在php 7.3的环境下运行,同样的代码

 #composer  install --no-dev --prefer-dist -vvv  

可以正常运行,而且也不会安装dev依赖的包

php扩展管理工具composer的坑、常见问题和解决方法

服务器要不删除,要不降低版本,即使不安装这个包

php扩展管理工具composer的坑、常见问题和解决方法

真是坑你没商量。

基本上就是哪里不行改哪里

 1、设置源
# composer config -g repo.packagist composer 
2、-vvv选项 
# composer install -vvv
3、设置内存
# php -d memory_limit=-1
4、不安装dev包
# /usr/bin/composer --no-dev install  

文章来源:智云一二三科技

文章标题:php扩展管理工具composer的坑、常见问题和解决方法

文章地址:https://www.zhihuclub.com/79044.shtml

关于作者: 智云科技

热门文章

评论已关闭

37条评论

  1. The effects of tadalafil on cardiac function, hemodynamics, and exercise tolerance were investigated in a single clinical pharmacology study

  2. In our present research, IELT and PEDT improvements were seen in both the tadalafil 5-mg and placebo cohorts, while the disparity between the drugs and placebo was not statistically significant

  3. Treatment-emergent AEs TEAEs These issues include organic soil revitalization, reduction of greenhouse gas emissions, solid waste remediation and point-of-use water purification solutions

  4. Mucinous colloid carcinoma is seen in fewer than 5 of invasive breast cancer cases 2015 Feb; 36 2 919 24

  5. Consequently, this agent would not be an optimal choice for use in a woman with osteoporosis Tamoxifen Nolvadex cost is also very affordable from a prescription it costs approx 1 a day

  6. I can t wait to see this drug start reaching men who could benefit from it on the NHS hopefully in the next couple of years

  7. Physiology of puberty Let s bear in mind that Paul McCartney s wife, Linda Eastman also led a 100 organic lifestyle she didn t have calcs but an aggressive tumor

  8. Cystic fibrosis CF is due to mutations in the CF transmembrane conductance regulator CFTR and CF related diabetes CFRD is its most common co morbidity, affecting 50 of all CF patients, significantly influencing pulmonary function and longevity

  9. Step H Methyl 3 benzyloxycarbonylamino 4 4 bis 2 chloroethyl amino 2 methyl phenyl butanoate 4h Following the General Procedure for of Description 7 Variant A, methyl 3 benzyloxycarbonylamino 4 4 bis 2 chloroethyl amino 2 methyl phenyl butanoate 4h was prepared from methyl 4 4 amino 2 methyl phenyl 3 benzyloxycarbonylamino butanoate 4g 200 mg, 0

  10. Speaking before 500 coalition members in Washington, she drew a roar of laughter with a comment on the breast squeezing mammogram apparatus that so many women hate It was indeed invented by a man, and I think there s a good tool we could invent for them with a little of our money

  11. However, scientific evidence that links antihypertensive drugs to sexual dysfunction in placebo controlled trials is limited, 2 and the question has been raised as to whether the higher rate of sexual dysfunction in hypertensive individuals is due to hypertension or to drug treatment of hypertension Effect of Tamoxifen on Lipoproteins

  12. Do you think clomid is better bcas their pituitary is working fine unlike secondary hypogonadism or others whos pituitary is not working

  13. Comorbidities were assessed from 24 to 3 months before diagnosis by using a modified list of conditions suggested by Elixhauser et al

  14. The use of Hydroxycut also has been linked to cardiovascular disorders, seizures, and rhabdomyolysis, a form of muscle damage which may lead to kidney failure

  15. Plank SFxJyRJYRaAtXuMCyeH 6 19 2022 Results will be displayed as a nomogram to provide clinicians with an intuitive and quantitative tool to predict the probability of complete NAFLD remission in obese patients

  16. Sugihara A, Adachi Y, Inaba M, Hisha H, Sugiura K, Miyashima S, Amoh Y, Taketani S, Oyaizu H, Ikebukuro K, Kawamura M, Genba H, Horio T, Ikehara S

  17. settled after one day of trial for 250 million, and, thus, the court s ruling in the Mylan case is being monitored closely by the plaintiffs bar

  18. We further performed single end metagenomic sequencing of three tablets of three additional oral probiotic supplements Culturelle L

  19. Early work by Lednicer in the 1960s 161 concluded that the presence of a basic group at a given position in space is required to obtain a molecule, which will antagonize the effects of concurrent estrogen administration The main virulence factors that lend to disease pathogenesis include production of a variety of extracellular enzymes, evasion of host immune response, and triggering intense tissue inflammation

  20. etravirine will decrease the level or effect of avanafil by affecting hepatic intestinal enzyme CYP3A4 metabolism

  21. Calcium phosphates are minerals composed of calcium cations and phosphate anions Hot flashes and other symptoms occur when ovarian function declines at menopause and hormone levels drop; the bigger the drop, the more pronounced symptoms may be

  22. She always called at the same time of day, which was great seeing as I knew to schedule my day around receiving the call

  23. Fasting blood sugar test Two successive values of this test which would possibly be equal to or larger than 126 mg dl verify diabetes mellitus The value of a random blood sugar take a look at in India is round Rs 150 The actual value may differ depending upon the city you reside in or the healthcare provider that you just choose There isn t any need to quick earlier than undergoing a random blood sugar old strips read high blood sugar check This check, as the name implies, is a random take a look at that can be conducted anytime, regardless of the fasting standing of the individual Completion of myPlaybook Coursework NAIA Academy as required by the NAIA National Drug

  24. dopamine, pulsatile flow, none of which have been proven efficacious in prospective, randomized trials

  25. Intensity of the red yellow fluorescence in ROI measurements indicates background and antibody accumulation for each organ

网站地图