I am planning to build a web application and am going to host it. Since hosting cost less for php and it being similar to .net i am planning to go for php.
I am basically a .net guy. But have no issues in learning php if it is similar to .net. Please give in your opinoins in doing so. Also please tell me if php supports asynchronous calls like the AJAX in asp.net. Give me your comments.
AJAX stands for Asynchronous Javascript And XML. PHP isn't mentioned anywhere, and doesn't need to be asynchronous to facilitate this.
The process is that a Javascript function calls a synchronous PHP page that returns results and the users browser is updated. The asycnhronous bit is that the javascript function doesn't block when it makes the call, and a callback function is fired when the PHP page returns.
I've implemented AJAX in PHP with no special programming above normal PHP HTML rendering and Javascript calls.
PHP has no built in support for asynchronous calls. You can make pseudo-asynchronous calls using curl.
If you plane to request MySQL, the MySQL driver bundled into PHP5.3 can make parallels queries. see the doc http://php.net/manual/mysqli.poll.php
You can also delegate tasks / emulate parallelism with gearman
Related
I like php, and I'm beginning to like java. I heard that jsp is officially deprecated (on the oracle website) and I'm trying to figure out how I could get data from a php script (from field data, image uploads) send it to my java program and have the results sent back to my php script.
Now I know I could use php for everything but some websites (such as google) use multiple back ends such as C and python.
There are several possibilities to interface PHP and Java. To name a few you coud try:
Make a Webservice in Java and call this Webservice in PHP.
Use another RPC protocol, like Thrift.
There is also the PHP/Java bridge.
Quercus is a PHP implementation in Java. When using this, you can just write functions in Java and call them from PHP.
PHP has experimental support for integrating Java.
I'm planning to build a Web App that would do massive use of AJAX and JavaScript, and I want to use PHP as the Server-Side language, with MySQL for the DataBase.
I found Raxan, and it looked really good, mainly because it would save me a lot of time with it's very easy integration with jQuery and AJAX calls. However, the project do not seems very alive or stable, and the forum is almos desert.
So, I would like to know what is the best framework suitable for a Web App that will do everything in a single page through AJAX calls.
PS: If it matters, I will use jQuery Mobile, and that's why everything will be in the same page.
Honestly, there isn't much to "PHP + AJAX" integrations. It's the same as "PHP + HTML". I would recommend you find a good PHP framework and a good JavaScript framework instead of looking for one that does both because they are always a mess since they are built by people that don't understand separating concerns.
I would recommend you having a look at Contao, but more information on what other features you want from a CMS are more important.
From the perspective of what you've described, Contao uses Mootools but can be mixed in with jQuery.
The core part of ajax queries is handled by an PHP executable in the root of the web server called ajax.php . This allows modules/widgets for FE or BE to communicate via AJAX calls and all nicely built in.
Don't worry about the Mootools part, since you could make a request using jQuery and it'll work seemsly with Contao and Mootools.
I am working on a PHP project that makes use of MLB's Gameday data. There appears to be a pretty solid Ruby library for working with data. I don't particularly want to rewrite the entire library in PHP, so I was wondering if anyone had any suggestions for a good way to interact with the Ruby scripts from my PHP application.
I'm starting to think that I'll need to write some sort of command line Ruby script that'll interact with the Ruby classes and output the data in a format usable by PHP (JSON, XML).
Are there any better ways to do accomplish this?
Another option is to use Gearman, written by the the same team that brought us memcached. It has PHP and Ruby bindings.
You'd create a daemon in Ruby that exposes functions to Gearman, then have your PHP code call those functions through Gearman. No Apache needed.
(Boy, I'm on a Gearman plugging streak. I wish I was getting paid for it!)
Rather then a command line interface, I'd suggest outputting data in JSON format and requesting that data via PHP & CURL.
If you needed to you could even write a REST interface for it pretty easily.
I'm new to PHP. I am familiar with ASP.NET which support asynchronous programming. That is, if one request needs to do some I/O job. It is suggested to program the web page with BeginProcess/EndProcess way. The asynchronous programming is key to improve scalability.
I'm wondering whether there is counterpart of asynchronous programming(BeginXXXX/EndXXXX) in PHP world.
In .NET BeginXXX/EndXXX paradigm relies heavily on threading, while on PHP I am not sure that you could even start a new thread (except maybe the PECL package).
FastCGI is the alternative to multithreading in most interpreted languages. Instead of spawning new threads it uses processes, but as spawning a new process is expensive, it keeps a reusable process pool just as the ThreadPool in .NET.
If the I/O is performed with sockets or files you should use stream_socket_select() or stream_select() respectively (similar to system calls in C/C++).
Here's a simple command line chat tutorial done with PHP:
Simple PHP socket-based terminal chat
Note: This is not a general multi-threading solution, but a simple solution for situations where you need "semi-parallel" I/O
The core has a set of process control functions, including the ability to fork a process.
I don't know that I'd use these in a web script, but have used them in command line scripts before.
http://www.php.net/manual/en/book.pcntl.php
http://www.php.net/manual/en/pcntl.example.php
Here's an interesting link on the subject of PHP multiplexing with PHP4 and PHP5 samples:
http://netevil.org/blog/2005/may/guru-multiplexing
PHP doesn't, but you could use AJAX once the page has loaded, which will allow asynchronous requests.
Honestly though, there is no point. If you really want that heavyweight of a back end, you're better off writing a separate program that does the heavy lifting. PHP modules are written in pure C as far as I'm aware, so you should be able to use that and then call your own custom function from PHP.
Using stream_select you can create child processes via a HTTP request. Checkout the code in http://drupal.org/project/httprl for some ideas on how to do this. I plan on pushing this library to github once I get it more polished; something that can be ran outside of drupal. But for now it lives in Drupal land.
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.