当前位置:网站首页>[Huang ah code] Why do I suggest you choose go instead of PHP?
[Huang ah code] Why do I suggest you choose go instead of PHP?
2022-07-07 17:08:00 【Yellow Size】
【 Say something old :php Is the best language in the world 】
Many developers think that php It's already “ spent force ”, It's time to turn go 了 , But before that , Let's have a good understanding of the difference between the two , If you don't even know the difference ? What else can we talk about
The simple difference
Go Also known as Golang, It is basically a programming language , It can be used for fast machine code compilation . It consists of Google establish . It is a statically typed compilation language . It provides a concurrency mechanism , It is easy to develop multi-core and networked machine level programs . It's fast , Dynamic typing and interpretation language .
PHP It's a server-side script , For Web General programming language for development and design ; It is a fast and flexible language of dynamic type . It can work with all kinds of Web Template system and Web The development framework is used in combination . adopt PHP The code processed is usually composed of PHP Interpreter implementation .
1、Go It is basically a programming language that can be used for fast machine code compilation , and PHP It's basically a server-side script , It's also used for Web Development of a general programming language .
2、Go Is a statically typed language .PHP It is a dynamically typed language .
3、PHP Use the core PHP Language templating , So the browser sends HTML Code processing PHP Code and send the output to the browser , And in the GO Under the circumstances , It usually uses a simple template system .
4、Go Its main application is machine level learning and its corresponding data science and artifact analysis .PHP Mainly used in Web The development process .
5、Go And other versions have a lot of community support , And get Google Support for , Its community support ratio PHP A little bit more .
Detailed differences
Grammatical differences :
One 、 Variable definition and assignment
Here you can clearly highlight the syntax differences between the scripting language and the compilation language
PHP: Weakly typed variables , The same variable can be assigned any data type at will
GO: Strongly typed variables , Variables need to be predefined , Different data types cannot be assigned randomly
Two 、 Function definition and return
Go Multi value return is more convenient ,PHP In some cases of single value return, it is necessary to judge the element isset($data['nickname'])
PHP: Function allows only a single value to be returned
GO: Function can return multiple values , And the data type needs to be defined for the parameter returned
3、 ... and 、 array ( Array )
PHP It is more convenient and powerful to deal with arrays ,GO When defining a multidimensional array, consider the type , It's a little cumbersome
PHP: Define an array variable , There is no need to consider the multi-level embedded assignment of arbitrary element types
GO: Need to distinguish the score group ( Fixed length )、 section 、 mapping 、 Interface
Four 、 Throw exception mechanism
GO It is not recommended to use try catch Catch exceptions in this way , You should check for errors before compiling , Many people have roast about this .
PHP:try and catch It can friendly catch the abnormal error handling of the non-standard code
GO: Different from other languages ,panic If not recover() It will make the whole main program exit unavailable
5、 ... and 、 Determine whether an element exists
PHP It is relatively concise , Built in function judgment ,GO Judgment seems a little less human
PHP: Simple use in_array And isset that will do
GO: The slice type must be determined by traversal ,Map The mapping needs to return the value for judgment
6、 ... and 、 Inherit
GO The design idea is not object-oriented programming , So there is not much inheritance and polymorphism , Writing ideas need to change .
PHP:extends Keywords inherit the methods and properties of the parent class
GO:struct Structure defines member attribute variables , So that inheritance
Performance difference
We use a server configuration here apache Test it
Server configuration : 16 nucleus E5620 @ 2.40GHz 11G Memory
Business includes :DB(oracle) and redis Inquire about , When there is a cache ,DB No more inquiries , Direct reading redis, Batch query two primary keys
Use apache Of ab test Concurrent 200,20000 A request
golang Concurrent test
golang Of qps Around the 9675/s, The highest 10200/s about ,cpu The peak utilization rate is 10.6% Up and down golang Multi core enabled , And maintained 40 individual redis Connection pool
above php The link to is golang Of url rewrite , For compatibility php Project
PHP Concurrent test
php Of QPS It's about 1726/s, The highest 2100/s about , cpu Peak in 50.1% It's scary
In addition, we also tested more batch queries of primary keys , golang The processing capacity of is reduced to 4700/s, php To 1078/s, take ab Concurrent add to 400 when , php Requests begin to fail ,
golang The concurrency of is added to 2500 after , Surprised that his performance is still excellent , Those who have doubts can test by themselves
The conclusion drawn from the above test results : Due to multi-core utilization ,golang Of ” Multithreading ”, also redis Connection pool , bring go In the and php The concurrent comparison is far ahead , The processing capacity is about php Of 4 times
In fact, many developers say it can be used swoole Frame blessing php, but swoole Or at the bottom C, The cost of learning is still quite high , My personal suggestion is to study as soon as possible go perhaps java Well , After all : If a programmer can't speak three or two languages , There is no guarantee for your future 【 remember , I'm talking about programmers , It's not an engineer !】
边栏推荐
- 浅谈 Apache Doris FE 处理查询 SQL 源码解析
- skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
- skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
- skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
- SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
- LeetCode 1477. Find two subarrays with sum as the target value and no overlap
- LeetCode 1031. 两个非重叠子数组的最大和 每日一题
- QML初学
- 预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
- 【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
猜你喜欢

Sator launched Web3 game "satorspace" and launched hoobi

Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls

SlashData开发者工具榜首等你而定!!!

How to add aplayer music player in blog

Pychart ide Download

掌握这个提升路径,面试资料分享

Pisa-Proxy SQL 解析之 Lex & Yacc

node:504报错

Sort out several important Android knowledge and advanced Android development interview questions

如何选择合适的自动化测试工具?
随机推荐
DNS 系列(一):为什么更新了 DNS 记录不生效?
LeetCode 1155. 掷骰子的N种方法 每日一题
LeetCode 1186. 删除一次得到子数组最大和 每日一题
Sator launched Web3 game "satorspace" and launched hoobi
LeetCode 1626. 无矛盾的最佳球队 每日一题
QT 图片背景色像素处理法
编程模式-表驱动编程
mysql实现两个字段合并成一个字段查询
A tour of gRPC:03 - proto序列化/反序列化
Number of exchanges in the 9th Blue Bridge Cup finals
QT中自定义控件的创建到封装到工具栏过程(二):自定义控件封装到工具栏
LeetCode 1049. 最后一块石头的重量 II 每日一题
Sator推出Web3游戏“Satorspace” ,并上线Huobi
射线与OBB相交检测
Sort out several important Android knowledge and advanced Android development interview questions
LeetCode 1986. The minimum working time to complete the task is one question per day
ATM系统
LeetCode 1031. 两个非重叠子数组的最大和 每日一题
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
运算符