Composer是一个深受程序员喜欢的PHP依赖关系管理工具。最近它的源代码上的一处改动引起了大家热烈的讨论。改动其实只是增加了一行代码: gc_disable(); ,但为什么要增加这行代码的原因却让人很费解。 估计普通的PHP程序员对这行代码并不知道是干嘛的。但单
Composer是一个深受程序员喜欢的PHP依赖关系管理工具。最近它的源代码上的一处改动引起了大家热烈的讨论。改动其实只是增加了一行代码:gc_disable();
,但为什么要增加这行代码的原因却让人很费解。
估计普通的PHP程序员对这行代码并不知道是干嘛的。但单从语义的字面意思上可以猜出,它是要禁止PHP的垃圾收集器。没错,就是这个意思。
给那些想寻求技术解释的人说明一下,在Composer里,PHP的垃圾收集器浪费了大量的CUP资源,它试图收集由于Composer在解决程序依赖问题时候产生的成千上万的对象(这些对象是Composer用来表达依赖包内部规则的)。对象在不断的生产,它就一遍又一遍的收集,但事实上它什么都没收集到,但每次对象的生产都会触发它再次收集。
禁止PHP的垃圾收集器虽然阻止了PHP的高级功能,但却释放了大量的内存,这样,Composer有足够的内存来做自己的事情,而不是让它们浪费在什么垃圾都收集不到的活动中。经过这样的修改后,很多人都报告内存使用量大幅度下降。
为什么这个问题这么久了才被人发现?看起来原因是性能优化工具无法检测到垃圾收集器的工作。很显然,这是性能优化工具的问题,期望以后后有所改进。但大多数情况下,这PHP的这个特征并不会成为一个问题,我不建议你们都在自己的项目中禁止垃圾收集器的工作。 在大多数情况下,PHP的垃圾收集器是非常有用的,只是在我们的Composer工具里它出现了问题。
上面的这段话是这段代码的修改人Seldaek在Hacker News上给大家的解释。
说的很清楚明白,消除了大家的疑惑,但这不是本文的重点,本文要说的重点是大家对这一重大修改的反应,全部体现在了Github的评论里。太欢乐了。你会发现程序员是最幽默的,下面选几个例子:
网友clemherreman评论:
Before: Memory usage: 163.66MB (peak: 403.82MB), time: 246.25s After: Memory usage: 163.34MB (peak: 350.36MB), time: 99.55s
网友martindines评论:
Before: Memory usage: 152.71MB (peak: 335.9MB), time: 195.99s After: Memory usage: 164MB (peak: 308.02MB), time: 104.06s
网友eXtreme评论:
Before: Memory usage: 217.37MB (peak: 631.42MB), time: 313.4s After: Memory usage: 174.62MB (peak: 495.42MB), time: 152.3s After latest commit: Memory usage: 174.88MB (peak: 495.1MB), time: 67.73s
网友j0k3r评论:
Memory usage: 385.05MB (peak: 910.03MB), time: 138.81s Memory usage: 384.93MB (peak: 863.22MB), time: 26.12s
网友youbs评论:
Before: Memory usage: 2194.78MB (peak: 3077.39MB), time: 1324.69s After: Memory usage: 4542.54MB (peak: 4856.12MB), time: 232.66s
网友johnpbloch评论:
Before: Memory usage: 43.34MB (peak: 69.12MB), time: 26.57s After: Memory usage: 43.67MB (peak: 60.27MB), time: 7.01s
网友o评论:
Our builds are now faster than ever!
网友oscherler评论:
Before: Memory usage: 272.95MB (peak: 898.45MB), time: 144.32s After: Memory usage: 257.05MB (peak: 608.25MB), time: 24.34s
网友raphaelstolt评论:
Memory usage: 94.01MB (peak: 163.47MB), time: 11.24s Memory usage: 87.91MB (peak: 123.66MB), time: 3.38s
网友malaney评论:
Before: Memory usage: 207.13MB (peak: 705.58MB), time: 762.59s After: Memory usage: 164.42MB (peak: 469.22MB), time: 53.98s
哦,太多了….
你是不是也乐了,这些搞技术的人是多么有趣一群人呀,生活中虽然有些寡言少语,但在工作中,在技术问题上,他们幽默、好学、欢闹的性格才真正的体现出来。
原文地址:PHP垃圾收集器和程序员的幽默, 感谢原作者分享。

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
