Is there a way to implement the "pagelets" concept using PHP as Facebook does? From their blog post:
BigPipe is a fundamental redesign of the dynamic web page serving system. The general idea is to decompose web pages into small chunks called pagelets, and pipeline them through several execution stages inside web servers and browsers. This is similar to the pipelining performed by most modern microprocessors: multiple instructions are pipelined through different execution units of the processor to achieve the best performance. Although BigPipe is a fundamental redesign of the existing web serving process, it does not require changing existing web browsers or servers; it is implemented entirely in PHP and JavaScript.
Pagelets in Facebook home page; each rectangle corresponds to one pagelet:
Is there a way to implement pagelets concept using PHP
No. It barely has something to do strictly with the server-side (PHP).
That is done in Javascript on the client (browser).
It appears that FB is referring to what is called the widget problem in MVC design. So this certainly appears backend, but the question is extremely open ended and impossible to answer.
I'd say go checkout some HMVC frameworks that allow you to do this.
The concept of pagelets is totally unrelated to PHP, however as you can do as well 3D graphics in PHP, there sure is a way to implement such a concept in PHP.
While you're at it, I would also suggest to implement the user-agent in PHP as well, so you can develop a cross-client-server-platform-pagelet implementation in PHP totally.
You might be looking for so called EDGE Side Includes for which you can find a PHP implementation in the Symfony2 framework. This also needs a server component, like Varnish or Squid.
Related
I'm currently creating a website using PHP and the Kohana framework. I want to site to be able to use real time (or near real time) data (e.g. for chat and real time feeds). I need it to be able to scale to thousands of concurrent users. I've done a lot of reading and still have no idea what the best method is for this.
Does anyone have any experience with StreamHub? Is it possible to use this with PHP?
Am I digging myself into a hole here and need to switch languages? I've looked at node js and nowjs, but I'm weary about coding a while site in Express (I wonder about security holes, code maintainability, lack of a good ORM). I've read about Twisted Python, but have no idea what web framework would work well on top of that, and I'd prefer not to use Nevow - maybe Django can be used well with Twisted Python? I'm just looking to be pointed in the right direction, so I don't go too far in PHP and realize I can't get the near real-time results that I need.
Thanks for the help.
I've looked at node js and nowjs, but
I'm weary about coding a while site in
Express (I wonder about security
holes, code maintainability, lack of a
good ORM).
I can personally vouch for code maintainability if you can do JavaScript. I personally find JavaScript more maintainable then PHP but that's probably due to lack of PHP experience.
ORM is not an issue as node.js favours document based databases. Document based databases and JSON go hand in hand, I find couch db and it's map/reduce system easy to use and it feels natural with json.
In terms of security holes, yes a node.js server is young and there may be holes. These are un avoidable. There are currently no known exploits and I would say it's not much more vulnerable
then IIS/apache/nginx until someone points a big flaw.
I want to site to be able to use real
time (or near real time) data (e.g.
for chat and real time feeds). I need
it to be able to scale to thousands of
concurrent users.
Scalability like that requires non-blocking IO. This requires a non-blocking IO server likes nginx or node.js (Yes blocking IO could work but you need so much more hardware).
Personally I would advice using node.js over PHP as it's easier to write non blocking IO in node. You can do it in PHP but you have to make all the right design and architecture decisions. I doubt there are any truly async non-blocking PHP frameworks.
Python's twisted / Ruby's EventMachine together with nginx, can work but I have no expertise with those. At least with node you can't accidentally call a blocking library or make use of the native blocking libraries since JavaScript has no native IO.
PHP is not the language you should be using for real-time updates of a website. PHP scripts load first before HTML (and HTML calls javascript files), so PHP cannot update your page for you. However, when used with AJAX (eg. using a jQuery function to call a PHP file to update your page in real-time), you can use PHP in this fashion.
Using jQuery and AJAX (all javascript), you can do quite a bit in terms of updating a page without reloading it. I've seen sites such as this one that demonstrate how to make a chat using jQuery.
I am working on a task where it is required to distribute live data (being fetched from some other server) to client using sockets. We user drupal as a framework and thus my choice of PHP.
1)I want to know the major factors that should be taken into consideration while developing this server.Like security,authentication,load etc and how should i approach this.Is there any blog/article that could be of help.
2)Is there a better choice than PHP for this?
3)ALSO is there any drupal module that could assist me in this.
I can think about one issue when you are talking about several servers connecting to you, you may want to conceder a nonblock mode.
Because when you are working with blocking mod, each server can connect at the time, meaning that there will be delay delivering the message.
http://il2.php.net/manual/en/function.socket-set-nonblock.php
I think java would be better choise, multi thread may help here.
from my point of view, this is something that you need to develop your self, socket programming needs a lot of attention.
Drupal is a Web CMS, it can be used as framework for advanced web features or light to medium web application that fits well in the traditional HTTP request paradigm. IMHO, distributing live data from multiple servers to client using sockets doesn't fit with the base assumption behind Drupal's design.
PHP can be used to write socket server. It used to be un-common, but it is becoming more and more available. ReactPHP is a non-blocking I/O library/framework suited for socket programing. Racthet is a websocket server in PHP using ReactPHP.
In any case, this would ne nothing like developing a web application with RoR, Drupal, Django, Symfony, etc.
If integration with a Drupal website is required, the Service module is a nice solution to provides a REST or XML-RPC API. Or course, direct access to Drupal's MySQL database is also an option but will probably require more knowledge of the used Drupal modules since you will have to replicate their behaviors and understand how they manage their data (for instance, how a particular CCK field is stored in your database).
Note: Previous version of this answer included reference to the following solutions in other languages: Twisted (Python), EventMachine (Ruby) and Node.js (JavaScript). These are all valid solutions when PHP is not required.
Previous version of the answer also referenced phpsocketdaemon, but nowadays ReactPHP is a more clean and robust solution.
When constructing a website, say a Q&A site or a just a forum site for a community, is just knowing HTML,CSS,PHP, MySQL, and javascript enough to make the site dynamic?
I am saying this because when I talked with my teacher, he said that major sites use many languages combined. And he said that a site shouldn't be designed only in PHP.
So is it possible to create a good website, not e-commerce, with only html,css, and php?
yes. there is no reason you should use more than one language internally. it makes making it all work together much easier in a server environment, where the extra load of IPC over function calls can slow things down considerably.
Ofc! :)
Lots of large/enterprise portals use only HTML, CSS, Javascript, PHP & MySQL.
But don't forget that there's always a right tool for the right job... A simple site (even an e-commerce) will run very well on PHP & MySQL.
Short answer: yes, it is possible.
Longer answer...
HTML, CSS, PHP and MySQL are already many languages, but I guess he means that most major sites have a heterogeneous back-end. This is probably not out of choice though -- more often it is historical. As people change and new technologies emerge, new pieces are built with different languages and frameworks.
I have built a forum and Q&A sites with HTML+CSS+PHP+MySQL and many other people have done the same, so this set of tools is without a doubt adequate for building something like this. In fact, I would argue that you could build almost anything on the web with that combination.
A more interesting question (that will generate more heated response) is what framework you use on top of that. A CMS like Wordpress of Drupal, or an MVC framework like Zend, CakePHP or CodeIgniter.
Or whether you should be dropping PHP entirely and using something like Django or Ruby on Rails. Knowing more than PHP will definitely help you to be ready for newer approaches.
The dynamism of a website comes from a server side language that can create a HTML output on the fly, that's it. You can add a DB, simple JS or AJAX, but those are merely optionals.
Now, as for your teacher, languages like PHP, Python and ASP are, in the end, the same. It's ridiculous to have the includes files in ASP, the main files in PHP and the configuration files in Python, that makes absolutely no sense. Maybe, hopefully, he was talking about using JS in conjunction with PHP and SQL which is a natural recommendation.
The fact that your teacher is obsessed with another technology doesn't mean that you can't work with PHP only.
As the others said, it is perfectly reasonable and possible.
(I'm personally obsessed with ASP.NET, but still, I won't say that it is the only way to go for everyone. And PHP is just geat for beginners.)
Is he referring to the front-end or back-end?
The front-end of a website - the part that the user sees and interacts with - must be written in HTML.
(It may optionally include CSS and Javascript to enhance it.)
The back-end is what generates the front-end, and also determines the structure and control-flow of the application.
There's absolutely no need to use more than one language for the back-end, and it's often simpler to stick to one language.
However, for the front-end, you have no choice but to use HTML; otherwise it isn't a web application.
The front end must output HTML. These days it should use CSS for formatting. It will likely use Javascript to provide client side capability. Requiring javascript will likely create accessability issues for some users.
PHP is one of several languages used to handle requests. It is in interpreted language requiring the source be placed on the server. This opens up significant security risk if the someone gets access to the server. Several hosting sites have had major problems with PHP based sites over the last few weeks.
Java is run in a compiled form and code is not required to be on the server. This provides a layer of security as it is not simple to modify the code. Java runs in a container, and usually a framework. Developing using the Spring framework in a Tomcat container is an option. The learning curve is higher than with PHP. It also has strong support for accessing remote resources which allows it to integrate with legacy applications.
With any of the languages, there is a risk that developers will use available functionality when they shouldn't. The Java J2EE model is appropropriate for some sites, but was often implemented because it was the fashion, and there are a lot of tutorials on using it.
We've got a large classic asp application and we consider migrating to either asp.net or php. I don't want to talk about the pros and cons of either one, but I'd rather like to know whether there are ways to avoid a complete rewrite in one shot when migrating to php. We simply can't stop maintaining the current codebase just to do a rewrite. So things have to go hand in hand.
If we'd move to asp.net, we should be able share session data among both technologies and have parts of the site replaced with new asp.net code, while other just keep on running. Is such an approach possible with php? Does anyone has got experiences with such a migration or could point me to some good readings?
The ability to share session state between ASP Classic and ASP.NET isn't an intrinsic feature of either language, though it's fairly easy to accomplish.
Microsoft provides sample code:
http://www.google.com/search?client=safari&rls=en-us&q=share%20session%20data%20between%20ASP%20and%20ASP.NET%20pages&ie=UTF-8&oe=UTF-8
By using Microsoft's example, you could pretty easily implement something similar in PHP. Basically you'd use the ASP Classic portion of Microsoft's code above. Then in PHP you'd write a fairly simple class to read session state from the database into an array or collection when each page is loaded. It's a little extra work in PHP, but shouldn't be more than a few extra days of coding and testing.
PHP runs pretty well on IIS6 in my limited experience and support for it is supposedly even better in IIS7. The only snag I've hit in is that a most of the PHP code out there assumes you're running on Linux/Unix... but generally this is only an issue for file-handling code (think: user image uploads) that works with local filesystem paths. Because they assume your filesystem uses / instead of \ like on Windows. Obviously fairly trivial to fix.
Good luck!
Yes; it is possible to share session data between ASP and ASP.NET pages on a single web application. We do that with our legacy code at my work.
I know it's possible to run PHP on the IIS. Not sure about sharing sessions between ASP and PHP scripts though.
"I'd rather like to know whether there are ways to avoid a complete rewrite in one shot when migrating to php"
Welcome to our world.
Our FogBugz codebase was written in classic ASP and when we wanted to offer it on Linux, the simplest solution was to write a compiler which read the asp and emitted php. It wasn't that difficult, and didn't take more than a few weeks.
The upside was when we decided to switch our entire application to .NET it only meant tweaking the compiler a bit to output .Net object code.
But to get back to your answer, ASP and PHP are VERY VERY similar and depending on your app there are really naive translators that might get you most of the way there.
Just another option. John Booty has a good suggestion too.
If the session data isn't sensitive information you can work cookies which will also be platform agnostic pending the user has cookies turned on.
That's probably not your best option given the post but another to think about.
Can I use Struts as a backend and PHP as front end for a web application? If yes, what may be the implications.
The first thing to came to mind is Quercus (from the makers of the Resin servlet engine), as Jordi mentioned. It is a Java implementation of the PHP runtime and purportedly allows you to access Java objects directly from your PHP (part of me says "yay, at last").
On the other hand, while I have been itching to try a project this way, I would probably keep the separation between Java EE and PHP unless there was a real reason to integrate on the code-level.
Instead, why don't you try an SOA approach, where your PHP "front-end" calls into the Struts application over a defined REST or SOAP API (strong vote for REST here) over HTTP.
http://mydomain.com/rest/this-is-a-method-call?parameter1=foo
You can use Struts to build your entire "backend" model, dealing only with business logic and data, and completely ignoring presentation. As you expose the API with these URLs, and you are basically building a REST API (which may come in handy later if you ever need to provide greater access to your backend, perhaps by other client apps).
Your PHP application can be built separately (and rather thinly), calling into the REST API (perhaps using Curl) as if it would call into a database or some native PHP class library.
Anyway, that's what I'd do. But, if you do use Quercus, please post how it went.
I don't know much about Java, but I remember running into Quercus a while ago. It's a 100% Java interpreter for PHP code.
So yes, you could have PHP templates on your Java app. Update: see Quercus: PHP in Java for more info.
What do you mean by backend and and frontend?
If you mean using Java for the admin side of your site and PHP for the part that the public will see then there is nothing stopping you.
The implications are that you will have to maintain two applications in different languages.
I think what you mean is you want to use PHP as your templating language and structs as your middleware (actions etc).
I would imaging the answer would be no, not without some kind of bridge between the structs session and the PHP.
If you say change x to 3 in java in a structs action, you couldn't just go <?php echo x ?> or whatever to get the value out, you would need to transfer that information back and forth somehow.
Submitting would be OK though, I would imagine.
Not recommended though.