본문 바로가기
개발 관련 학습 및 문제해결

php 언어의 특징과 장단점[20221018 TIL]

by 날파리1 2022. 10. 18.

포트폴리오에 들어가기 전에 기술스택을 조사하던 중 php 언어가 웹개발에 많이 쓰인다는 것을 발견했다. 아직 백엔드 언어로는 자바와 스프링만 배웠기에 다른 언어의 특징을 접하고 알아볼 기회는 없었는데 현업에서는 다양한 상황에서 다양한 언어를 활용하고 배우는 능력이 중요함과 동시에 왜 이 언어를 사용해야하는지를 이야기할 줄 알아야한다는 트레이너님의 조언을 듣고 조사를 해보기 시작했다.

 

php란?(Personal Hypertext Preprocessor)

What is PHP?

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

Nice, but what does that mean? An example:

Example #1 An introductory example

<!DOCTYPE html>
<html>
    <head>
        <title>Example</title>
    </head>
    <body>

        <?php
            
echo "Hi, I'm a PHP script!";
        
?>

    </body>
</html>

Instead of lots of commands to output HTML (as seen in C or Perl), PHP pages contain HTML with embedded code that does "something" (in this case, output "Hi, I'm a PHP script!"). The PHP code is enclosed in special start and end processing instructions <?php and ?> that allow you to jump into and out of "PHP mode."

What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was. You can even configure your web server to process all your HTML files with PHP, and then there's really no way that users can tell what you have up your sleeve.

The best part about using PHP is that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don't be afraid to read the long list of PHP's features. You can jump in, in a short time, and start writing simple scripts in a few hours.

Although PHP's development is focused on server-side scripting, you can do much more with it. Read on, and see more in the What can PHP do? section, or go right to the introductory tutorial if you are only interested in web programming.

 

php 란 널리 사용되는 오픈소스의 스크립트 언어이며 특히 웹 개발에 특화되어있다고 한다. (근데 어떻게가 잘 나와있지 않다.)

 

HTML 코드를 포함한다.

PHP pages contain HTML with embedded code that does "something" (in this case, output "Hi, I'm a PHP script!"). The PHP code is enclosed in special start and end processing instructions <?php and ?> that allow you to jump into and out of "PHP mode."

 

클라이언트 사이드 언어인 자바스크립트와 구분되는 것은 php 는 코드에서 구현된다는 것이다.( 그래서 server side scripting 언어라고 한다.)

What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is then sent to the client. 

 

What can PHP do?(PHP 는 무얼할 수 있나?)

Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more.

There are three main areas where PHP scripts are used.

  • Server-side scripting. This is the most traditional and main target field for PHP. You need three things to make this work: the PHP parser (CGI or server module), a web server and a web browser. You need to run the web server, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server. All these can run on your home machine if you are just experimenting with PHP programming. See the installation instructions section for more information.
  • Command line scripting. You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks. See the section about Command line usage of PHP for more information.
  • Writing desktop applications. PHP is probably not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way. PHP-GTK is an extension to PHP, not available in the main distribution. If you are interested in PHP-GTK, visit » its own website.

서버사이드 스크립팅에 초점을 맞춘 PHP 는 뭐든 할 수 있다. 다른 CGI 프로그램이 하는 어떤 것(폼데이터를 모으거나 동적인 페이지 컨텐트를 만들거나 쿠키를 보내고 받는 등의)이든 할수 있다. 하지만 PHP는 더 많은 것을 할 수 있다.

- 서버 사이드 스크립팅. 이것은  php 언어의 가장 전통적이고 주된 필드이다. 당신은 다음이 필요하다..(중략)

- 커맨드 라인 스크립팅. php 스크립트를 어떤 서버나 브라우저 없이 작동시킬 수 있다.

- 데스크탑 어플리케이션 쓰기. PHP는 데크스탑 어플리케이션을 그래픽 사용자 인터페이스로 만들기에 베스트는 아닐지도 모른다. 하지만 php를 잘 안다면 클라이언트 사이드 어플리케이션속에서 php의 더 많은 기능을 사용할 수 있다.(이것도 장점인 줄 잘 모르겠다..)

 

추가로 찾은 정보

php 단점

It entirely is suited to all types of projects. It has a lot of pros and cons going each way, and there's a Stack Overflow answer I did a few years ago on this topic

The reason why PHP is disliked for the purpose you've askes about is in the question itself; because its easier, quicker and faster. Three terms that do not offer stability, redundancy and performance.

You're only as good as your tools, and your project is only as good as your team, so you can produce gold in any language, as well as complete dross. PHP is unfavoured for those types of projects because of its dynamic nature, its one true strength.

But as PHP evolves and becomes more reliable, predictable, performant and adopts some good practices (while constantly introducing shit ones like mixins), it becomes more attractive as an option.

.Net and Java are favoured for enterprise development because of their static nature, stateful runtime, scalability, multi-threaded environment and ability to process more.

Perhaps one of the biggest issues is that to build enterprise, there isn't really a starting point in PHP. You end up using libraries, some that perform better than others, are modular, or easy to integrate. The trade off in almost every single situation is performance. PHP needs a ton of memory to run efficientlt, like GBs to TBs in an enterprise environment, as well as memcached and other caching services in a distributed and scaled manner.

PHP can scale, but it can also ve a nightmare. But like I said, your product is only as good as your team, and if your team is great and savvy, you can polish a turd in any language, and you can certainly create that turd too.

 

요약 : 스몰프로젝트에 알맞다. 빠르고 쉽기 때문에 이것의 다른 말은 안정성과 퍼포먼스가 약하단 말이다. 우리는 모두 도구의 기능만큼 유능하다 -> 즉 도구의 한계치만큼만 우리 능력을 발휘할수 있다.(php가 풀 퍼포먼스를 발휘하기엔 약하다는 뉘앙스)

 

프로그램의 크기가 커질 수록 관리가 어렵다는 뜻으로 알아들었다.

 

 추가로 php로 웹에서 간단한 계산기만드는 코드를 공부해 보았다.

 

내 결론!

코드안에 html 코드가 들어있어서 뷰 와 로직의 구분이 애매하다.

빠르고 쉽게 배울수 있어서 좋다.

사이즈가 큰 앱에서는 안정성과 퍼포먼스때문에(스크립트 언어이기 때문에 컴파일 언어보다 속도가 떨어진다.) 부적합하다.

 

액션플랜

내일 추가 기술스택 장단점 정리해서 티아이엘에 쓰고 노션에 정리하기!

댓글