If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

PHP vs. Perl

Started by ipt, Aug 09, 2022, 12:19 AM

Previous topic - Next topic

iptTopic starter

Hello there! I have some queries:

After writing in PHP for a considerable period of time, I have noticed that many prominent companies have a higher demand for Perl instead of PHP. Moreover, some reviews suggest that Perl is faster than PHP in terms of script execution, but I am not certain if this is true or not.

I have also read about certain drawbacks of Pearl, such as the 500th error and difficulty in processing data obtained from forms. Although some modules can fix these issues, it remains unclear if hosting them would be a problem.

Additionally, I am curious to know if it is advisable to keep all scripts in cgi-bin or if there are other more suitable options available. It is admittedly inconvenient that regular HTML pages cannot be placed in this directory after coming from PHP.

On the whole, it is essential to explore alternative options and weigh their pros and cons before making a decision.
  •  


RoyJones

Non-compilation modules can be simply placed alongside the script and accessed through the full path. If the hosting provider furnishes development tools, a module that necessitates compilation can be installed.

Regarding PHP vs Perl, PHP is already a significant language (though some of its features are endearing), but it possesses noticeable simplicity as well. Hence, novice web writers prefer to start their ventures in PHP. As a consequence, there are many more substandard and inadequate PHP scripts than there are in Perl. Basically, an active attempt to lower the bar for entry into PHP has resulted in a tarnished image.

However, one can also write serious code in PHP. Speaking as a Perl programmer with 9 years of experience, I can say that Perl is 50% a regular expression language that has been emulated by several programming languages (including PHP). Even Unix console utilities are gradually shifting from POSIX regexp to pearl ones. Therefore, it is worth familiarizing yourself with Perl, at least from this perspective.

In my opinion, if you have access to PCP, write code on it. If you have time and interest, learning Perl is not detrimental, but advantageous as it expands expertise. In terms of calling a perl, there is not much difference from PHP; both use the same principle for calling (e.g., from Apache via the handler), and it is the web server that makes the distinction.

Usually, PHP handler is assigned to the file extension, whereas perl and other CGI handlers must be called using the ScripAlias folder. Nevertheless, the web server has provided means to modify this principle, which is even available through .htaccess. For Apache, I recommend reading http://httpd.apache.org/docs/. If you manage the web server, there are two modules for Apache - embedded Perl solutions - one for mod_perl, the other for working with regular Perl.

Lastly, for errors, each server has an error_log. If your hosting provider does not allow access to this file, then it's time to switch providers, as the file is highly beneficial.
  •  

mdillinger

The fundamental difference between Perl and PHP lies in their very nature. Perl is a universal programming language that can solve a broad array of problems, whereas PHP was designed solely for web application development, striving to balance the power of a fully-fledged language with the benefits of a highly specialized tool. Consequently, PHP has garnered some contentious qualities in its quest for a compromise.

Perl, like any complete language, has a core - a set of functions and rules that do not depend on platform or operating system. By contrast, PHP lacks such a solid foundation and depends instead on the provider. Hence, it possesses several distinct features. Perl code is more portable and consistent, while PHP runs into compatibility issues when the hosting provider does not have the essential extensions.

PHP offers a potentially vast range of functions, with over 3000 to choose from. However, the actual number available on real hosting site only amounts to about a third. In contrast, Perl provides the programmer with a limited but effective set of standard tools, ensuring readability and smoother exchange of code and experience.

Moreover, PHP syntax has become unwieldy due to the unavoidable lengthening of function names. For example, what is called pop in Perl is array_pop in PHP. Although the two languages share some similarities, programs that look similar in one are often more cumbersome and verbose in the other when it comes to solving the same problem.

Lastly, Perl is a much more mature language than PHP, highly resistant to changes in versions and equipped with advanced development tools.
  •  

bayilucu

The discussion around performance is quite relevant; while Perl can be faster in certain scenarios due to its text-processing capabilities and efficient execution of regular expressions, PHP has been optimized over the years, especially with the introduction of PHP 7, which brought significant performance improvements. The speed difference may not be as pronounced unless you're handling a massive load of data or complex operations.

Regarding the drawbacks of Perl, you mentioned the 500 Internal Server Error, which is indeed a common issue that arises from misconfiguration, particularly in the CGI environment. This can stem from various factors, including incorrect permissions or syntactical errors within the script itself. To combat this, it's advisable to have thorough error logging enabled to trace the specific issues, as well as ensure that your shebang line at the top of your scripts is correctly pointed to the Perl interpreter.

Form data processing in Perl can be less intuitive compared to PHP, primarily because PHP was designed with web development in mind. However, modules like CGI.pm can help manage forms more easily, though they can introduce a layer of complexity, especially if you're not familiar with Perl's object-oriented aspects. While these modules can resolve issues, hosting providers may have restrictions on the version of Perl or the modules installed, so checking with them is crucial before implementation.

As for organizing scripts, traditionally, CGI scripts are placed in the cgi-bin directory for security reasons. It's true that this directory typically restricts the types of files it can serve, limiting you to executable scripts. However, modern best practices advocate for placing scripts outside of the web root to prevent direct access and using a URL rewriting technique to handle requests better. This can help you serve regular HTML pages from the main directory without the constraints of the cgi-bin.
It's wise to evaluate the project requirements carefully. While Perl offers certain advantages, PHP's ease of use, broad community support, and the vast ecosystem of frameworks may outweigh its speed in most web applications. Always consider the hosting environment, your team's familiarity, and the long-term maintenance of your codebase. Making an informed decision involves weighing these factors alongside the specific needs of your projects.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...