Table of Contents
1. 如果要快速开发,可以考虑使用MVC框架
2. 將 error_reporting 设为 0 未必万事大吉
3. 试试在 Linux 上开发
Home php教程 php手册 PHP开发的几点想法记录

PHP开发的几点想法记录

Jun 13, 2016 am 09:39 AM
development environment frame

1. 如果要快速开发,可以考虑使用MVC框架

使用像 CodeIgniter 这样的MVC框架了在快速开发中很有效,MVC框架并不强迫你写面向对象的代码,它们仅將php代码与html分离。

  • 明确区分php和html代码,在团队协作中有好处,设计师和程序员可以同时工作。
  • 面向对象设计的函数能让你更容易维护。
  • 内建函数完成了很多工作,你不需要重复编写。
  • 开发大的应用是必须的。
  • 很多建议、技巧和hack已被框架实现了。

2. 將 error_reporting 设为 0 未必万事大吉

错误报告 E_FATAL 错误是很重要。

ini_set('display_errors', 1);
error_reporting(~E_WARNING & ~E_NOTICE & ~E_STRICT);

注意:

  1. 这个让 web 服务器记录错误信息的文件 '/path/to/errors.txt' 应该让 web 服务器具有可写的权限。
  2. 这个错误日志文件要独立开来。否则所有的各种日志,包括 apache web 服务器的日志、其它的错误日志都将混杂在一起了。
  3. 而且,为当前应用程序设置的错误日志文件应该只记录了当前应用程序的错误日志(有可能web 服务器上还运行了其它的应用程序)。
  4. 应用的错误日志应该放在当前应用程序的某个目录下,使得像 /var/log 这样的系统目录不再需要去寻找。
  5. 不要设置 error_reporting 为 0。这会使得所有发生的一切都不会被记录。

另外,set_error_handler 应该被用于设置一个用户自定义的错误处理方法。例如,这个特有的功能,可以记录所有的错误到一个文件中。

在开发环境的 php.ini 中设置  'display_errors=On'

在开发环境的 php.ini 里,启用 display_errors 的权限是很重要的 (且不要依赖于 ini_set 的设置)。这是因为任何编译时发生的错误都不允许 ini_set 来运行,这会导致出现一个空白页面而没有任何错误信息被显示出来。

同样的,在 php.ini 中设置为了 on,但在代码中把其设置为了 off,那么错误发生时同样显示不出来。

在产品环境的 php.ini 中设置 'display_errors=Off'

不要依赖于代码 init_set('display_errors' , 0); 因为如果编译时代码发生错误,那么这条语句就不会被执行,而错误信息就会马上显示给了客户。

3. 试试在 Linux 上开发

如果你已经在 windows 系统上进行开发了,那么你可能需要试试在 linux 上做开发。我最喜欢的 Linux 是 Ubuntu。虽然这只是可选的开发环境之一,但我仍然强烈地感觉到 linux 开发环境是一个更好的开发环境。

PHP 应用通常被部署到 linux (LAMP)环境中。然而,在类似的开发环境能够帮助一个健壮的应用程序跑得更快。

在 Ubuntu 系统上,通过安装包管理器,大多数开发工具都可以非常容易地安装到系统中。除此之外,仅通过少量的配置就可以设置好他们并跑起来。而最美妙的是,这些工具都是免费的!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to evaluate the cost-effectiveness of commercial support for Java frameworks How to evaluate the cost-effectiveness of commercial support for Java frameworks Jun 05, 2024 pm 05:25 PM

Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

How does the learning curve of PHP frameworks compare to other language frameworks? How does the learning curve of PHP frameworks compare to other language frameworks? Jun 06, 2024 pm 12:41 PM

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

How do the lightweight options of PHP frameworks affect application performance? How do the lightweight options of PHP frameworks affect application performance? Jun 06, 2024 am 10:53 AM

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

Performance comparison of Java frameworks Performance comparison of Java frameworks Jun 04, 2024 pm 03:56 PM

According to benchmarks, for small, high-performance applications, Quarkus (fast startup, low memory) or Micronaut (TechEmpower excellent) are ideal choices. SpringBoot is suitable for large, full-stack applications, but has slightly slower startup times and memory usage.

Golang framework documentation best practices Golang framework documentation best practices Jun 04, 2024 pm 05:00 PM

Writing clear and comprehensive documentation is crucial for the Golang framework. Best practices include following an established documentation style, such as Google's Go Coding Style Guide. Use a clear organizational structure, including headings, subheadings, and lists, and provide navigation. Provides comprehensive and accurate information, including getting started guides, API references, and concepts. Use code examples to illustrate concepts and usage. Keep documentation updated, track changes and document new features. Provide support and community resources such as GitHub issues and forums. Create practical examples, such as API documentation.

How to choose the best golang framework for different application scenarios How to choose the best golang framework for different application scenarios Jun 05, 2024 pm 04:05 PM

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.

What are the common misunderstandings in the learning process of Golang framework? What are the common misunderstandings in the learning process of Golang framework? Jun 05, 2024 pm 09:59 PM

There are five misunderstandings in Go framework learning: over-reliance on the framework and limited flexibility. If you don’t follow the framework conventions, the code will be difficult to maintain. Using outdated libraries can cause security and compatibility issues. Excessive use of packages obfuscates code structure. Ignoring error handling leads to unexpected behavior and crashes.

Detailed practical explanation of golang framework development: Questions and Answers Detailed practical explanation of golang framework development: Questions and Answers Jun 06, 2024 am 10:57 AM

In Go framework development, common challenges and their solutions are: Error handling: Use the errors package for management, and use middleware to centrally handle errors. Authentication and authorization: Integrate third-party libraries and create custom middleware to check credentials. Concurrency processing: Use goroutines, mutexes, and channels to control resource access. Unit testing: Use gotest packages, mocks, and stubs for isolation, and code coverage tools to ensure sufficiency. Deployment and monitoring: Use Docker containers to package deployments, set up data backups, and track performance and errors with logging and monitoring tools.

See all articles