Home  >  Article  >  Backend Development  >  Top Ten Key Points to Master PHP (Part 1)_PHP Tutorial

Top Ten Key Points to Master PHP (Part 1)_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:48:11981browse

1. 在合适的时候使用PHP - Rasmus Lerdorf
没有谁比PHP的创建者Rasmus Lerdorf明白PHP用在什么地方是更合理的, 他于1995年发布了PHP这门语言,从那时起,PHP就像燎原之火,烧遍了整个开发阵营,改变了互联网的世界。 可是, Rasmus并不是因此而创建PHP的PHP是为了解决web开发者的实际问题而诞生的。

和许多开源项目一样,PHP变得流行,流行的动机并不能用正常的哲学来进行解释,甚至流行得有些孤芳自赏。它完全可以作为一个案例,一个解决各种web问题的工具需求所引起的案例,因此当PHP刚出现的时候,这种工具需求全部聚焦到PHP的身上。

 

但是,你不能奢望PHP可以解决所有问题。Lerdorf是第一个承认PHP只是一种工具的人,并且PHP也有很多力所不能及的情况。

根据工作的不同来选择合适的工具。我跑了很多家公司,为了说服他们部署和使用PHP,但是这并不意味着PHP对所有问题都适用。它只是可以一个解决大部分问题的front-end脚步语言。

作为一个web开发者,尝试用PHP解决所有问题是不科学的,同时也会浪费你的时间。当PHP玩不转的时候,不要犹豫,试用一下其他的语言吧。

2. 使用多表存储提高规模伸缩性 - Matt Mullenweg

没有人愿意质疑Matt Mullenweg在PHP方面的权威性,他开发了这个星球上最流行的blog系统,(依靠一个强大的社区力量支持): Wordpress. 创建Wordpress以后,Matt和他的团队启动了Wordpress.com平台,一个基于Wordpress MU的免费blog站点。现在,Wordpress.com已经拥有大约400万用户, 这些用户每天提供超过 140,000篇的日志。 (要查看更多Wordpress.com的统计情况,请点击这里.)

如果有人知道如何让网站的规模伸缩自如,这个人一定是Matt Mullenweg。2006年的时候 Matt对Wordpress的数据结构进行了前瞻性的改进,并且解释了为什么Wordpress MU对每个blog使用独立的MYSQL表格, 而不是把所有的blog数据都塞进一个巨大的表格。

我们测试过这个方法,但是发现如果要扩展它的伸缩性,代价太高。如果用一个整体的数据结构,在大流量面前,你将会面临服务器硬件的问题。在MU里面。用户们都被分布到独立的表格当中,并且可以轻易地组织起来。举个例子,WordPress.com把用户的数据分散存储到4096个数据库中,这些数据库可以分散大规模的数据访问,实现流量和压力分流。

数据表的可迁移性让代码(blog)可以运行得更快,并且让系统具备更强的伸缩性。依靠强大的缓存策略和灵活的数据库运用策略, Matt向人们展示了时下最流行的Facebook和Wordpress.com都可以在PHP下稳定运行,并且处理惊人的访问量。

3. 千万不要相信用户 - Dave Child

Dave Child是 Added Bytes (previously ilovejackdaniels.com) 网站的核心人物,这个网站以他出色的《cheat sheets for many programming languages》而闻名。 Dave为很多英国的公司服务,并且已经在编程世界里树立起相当的权威。

Dave为PHP开发者提供了很多深谋远虑的建议,并总结成了《writing secure code in PHP》:千万不要相信你的用户,他们甚至可能会伤害你。

有一条web开发的基本原则,我重复多少遍都觉得不够,那就是:千万不要相信你的用户,同时要假设你网站中的每个数据单元都是从用户那里收集来的恶意代码。很多时候,你必须用javascript在客户端检验表单提交过来的内容, 如果你习惯了如此,那么,这是一个好习惯。如果安全性对你来说很重要,这就是最重要最需要学习的原则。

Dave目前正致力于为它的《Writing Secure PHP》系列书籍整理实例,书的最后他说:

最后,变得偏执一点吧。除非你认为你的站点永远不会受到攻击,否则就正视所有的问题,当问题真正发生的时候,你的情况会变得很糟。你需要把每个用户都看成会带来一场攻防站的黑客,想尽一切办法来保护站点的安全,同时想好相应问题的解决方案。

4. 多使用PHP缓存 - Ben Balbo

Ben Balbo开发了Site Point,一个为developers和designers提供指导的网站。他是墨尔本PHP开发和开源俱乐部的成员, 因此他对PHP有一定的了解,同时对PHP caching有一定的想法和经验。

如果你拥有一个访问量很大,但更新并不频繁的站点(比如blog,基于某种CMS),或许它需要进行一些改造,这些改造不会花费太多的时间,但是对性能有突出的贡献。 如果要为一个复杂/更新频率很快的站点建立缓存机制,过程可能会很曲折,但是好处也是显而易见的。

PHP缓存技术有很多种,Ben为我们推荐了如下一些:

缓存函数的运行结果
设置过期时间
缓存IE下载的文件
模板缓存技术
Cache_Lite

由于PHP作为动态语言的特性,缓存机制对于更新频率并不快的站点来说非常重要。

5. 使用IDE, Templates和Snippets加速PHP开发 - Chad Kieffer

当Chad Kieffer从UI设计和数据库优化的工作中抽身出来的时候,他会在他的博客2 tablespoons上分享很多技术经验。由于Chad多方面的全面发展,他经常可以发现其他程序员不能发现的问题,并形成相关经验,尤其是他开发网站的方法。他参与了网站开发的各个环节,因此他的建议对于提高网站开发的大局观非常有用。

Chad认为使用Eclipse PDT
(Eclipse's PHP development package) 这样的IDE,同时使用一些模板技术和开源项目可以有效地提高PHP的开发速度。

紧凑的计划,长长的to do lists以及deadlines让开发人员非常苦闷。不过有些功能,比如Eclipse Templates,可以有效减少编码的时间和出错的几率。

通常来说,任何项目都可以自动化,自动化程度越高, 你完成项目的时间就越短。花时间来开发使用频率很高的框架和模板,将会节省你以后更多时间。同时,使用像Eclipse and the PDT package这样的IDE,你会发现效率得到明显提高,IDE可以自动闭合,补全分号并且可以在本地debug。

Related posts:

  1. Wordpress was successfully upgraded to 2.3.2 Although tags are of no use to me, but focusing on security, I still upgraded from 2.0.5 two years ago Upgrading to the current 2.3.2 really requires courage and determination. Fortunately, there were no problems when running the upgrade locally. Only the functions on the template need some simple modifications. The online upgrade went smoothly. Many people will be wondering, didn't you just post a post asking for help on how to upgrade? Well, I have found the best tool, WordPress Automatic Upgrade plugin. This WordPress automatic upgrade plugin really makes your upgrade worry-free, because it will back up all files and data for you before upgrading. It is also "all the way to next". " type, I believe it is very suitable for bloggers who don't want to worry about upgrading. However, there is a problem. There is a problem with the export function after the upgrade. It prompts that wp-config.php cannot be found. I don't know if this problem is common or a problem with my blog. , friends who encounter the same problem please leave me a message and I will research a solution. (After research, it was found that it turned out to be a problem with the access path in the coolcode plug-in. As long as the activation of this plug-in is cancelled, the Export function can be used normally) ...
  2. Does anyone have experience upgrading from WordPress 2.0? I downloaded wordpress-2.3.2 today. I originally wanted to upgrade, but I found that the version leap is quite large and the data structure changes seem to be quite large. , upgrading is too troublesome and risky, so I give up for the time being. Does anyone have experience in upgrading from WordPress 2.0 to 2.3? Please share it. Thank you very much. ...
  3. Translation: "14 Great Webmaster Tools" (Part 2) Original text: http://www.conversion-rate-experts.com/articles/understanding- your-visitors/ This article was independently translated by Andrew (http://www.achome.cn). If you need to reprint, please indicate the source. Users are the best publicity and sales personnel, come and listen to how they promote it, Tell-a-Friend King—experience it now! Do you have a user recommendation system? A system that allows users to send messages to invite friends. We can see that the letters sent by these users contain the answer to the question "Why do users spend money on your website?" Many people spend a lot of time positioning themselves and developing attractive advertising words, but through user testimonials, you can find out why users prefer you. Easily collect user feedback, Kampyle—try it now! Kampyle allows users to submit user feedback on your website (through a small button at the bottom of the page). After clicking, a window will pop up for users to fill in their opinions and suggestions. Webmasters can log in to Kampyle's official website to view and manage collected user feedback. If users leave their email addresses, webmasters can easily notify users that they have received feedback and will make corresponding improvements. ...

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319800.htmlTechArticle1. Use PHP when appropriate - Rasmus Lerdorf No one understands the use of PHP better than Rasmus Lerdorf, the creator of PHP What makes more sense, he released the PHP language in 1995, and since then...
Statement:
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