PHP and javascript

PHP and javascript

am 15.01.2010 20:07:39 von Andres Gonzalez

How do I call PHP code that will run server side, from javascript code
that is running client side?

I have a lot of PHP server side code written and working within
CodeIgniter. Now, my project
has changed and (for reasons unimportant to this discussion) we are now
NOT going to
use apache and CodeIgniter, but instead, we are going to have to use an
http server that does
not support PHP internally. But I want to reuse my original PHP code.
So I am thinking that I
can execute the PHP code via a command line interface using the PHP cli
interface instead of
the PHP cgi interface. But, I will have to initiate this serversid call
via javascript code running
on the client.

I know...kind of convoluted. But how would one do this if necessary?

-Andres

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP and javascript

am 15.01.2010 20:24:12 von Ashley Sheridan

--=-/CMrwIPNo8kP5eb4dYRZ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Fri, 2010-01-15 at 14:07 -0500, Andres Gonzalez wrote:

> How do I call PHP code that will run server side, from javascript code
> that is running client side?
>
> I have a lot of PHP server side code written and working within
> CodeIgniter. Now, my project
> has changed and (for reasons unimportant to this discussion) we are now
> NOT going to
> use apache and CodeIgniter, but instead, we are going to have to use an
> http server that does
> not support PHP internally. But I want to reuse my original PHP code.
> So I am thinking that I
> can execute the PHP code via a command line interface using the PHP cli
> interface instead of
> the PHP cgi interface. But, I will have to initiate this serversid call
> via javascript code running
> on the client.
>
> I know...kind of convoluted. But how would one do this if necessary?
>
> -Andres
>


I wouldn't recommend doing it this way at all. What you'd essentially
need, is Javascript make an AJAX request to a server script, which would
then call your PHP shell script, which would then return data to the
[other language] server script, that responds back to the Javascript on
the browser.

What sort of server will you be using that you can' support PHP on it?
PHP runs on most web servers out there, and will happily run alongside
other language modules on a single server.

Who's making the decisions about the new server? Someone really needs to
explain to him/her that it's a massive project converting a website from
one language to another (I've had to convert a large ColdFusion one to
PHP before, so I know) and it will probably cost more in the long term
to convert than might be saved on whatever server 'deal' they're
getting.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-/CMrwIPNo8kP5eb4dYRZ--

Re: PHP and javascript

am 15.01.2010 20:26:02 von Ryan Sun

--001636d34a9b5dd92f047d38f9b3
Content-Type: text/plain; charset=ISO-8859-1

I don't think you can call php cli from client javascript unless you have a
wrapper http interface

On Fri, Jan 15, 2010 at 2:07 PM, Andres Gonzalez wrote:

> How do I call PHP code that will run server side, from javascript code that
> is running client side?
>
> I have a lot of PHP server side code written and working within
> CodeIgniter. Now, my project
> has changed and (for reasons unimportant to this discussion) we are now NOT
> going to
> use apache and CodeIgniter, but instead, we are going to have to use an
> http server that does
> not support PHP internally. But I want to reuse my original PHP code. So I
> am thinking that I
> can execute the PHP code via a command line interface using the PHP cli
> interface instead of
> the PHP cgi interface. But, I will have to initiate this serversid call via
> javascript code running
> on the client.
>
> I know...kind of convoluted. But how would one do this if necessary?
>
> -Andres
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--001636d34a9b5dd92f047d38f9b3--

Re: PHP and javascript

am 20.01.2010 07:07:32 von Rene Veerman

To do what you want that new httpd server should at least be able to
call up PHP via cli / whatever, and retrieve the output.
It also needs to provide what's in php called $_GET and $_POST.

Assuming you got that covered, then yes, you could route the calls via
ajax (i recommend jquery.com for that) to your non-php httpd, which
then forwards it (and the results back).
What i'd do if it HAD to be done this way, is pass a couple of extra
variables in each call from javascript. It's best to route all the
ajax calls to php to the same script on the non-php httpd, so you'd
need at least the "relative path (from serverside defined absolute
base-path for your php subsystem) to the script being called" (or even
an MD5/SHA256 of this rel path, if you're on the paranoid side; you
then inform (via an array) the non-php httpd about all the scripts
that may be called from javascript, without giving up the scripts
names to spies along the line)

But tbh, whoever thought of changing the type of server used and
thereby giving you this new problem, should have also thought of how
to not-dump tons of existing code. Not to mention developer experience
with a specific language.

If this new httpd is so damn good at something that it has to be used,
it still doesn't mean it has to be used for the entire system either.
You might be giving it more work than it is comfortable with, that
way.

So depending on your backend size (in terms of number of machines
used) & setup, you might even campaign to keep an apache in the
picture and let it perform work on the database / file storage
system..

On Fri, Jan 15, 2010 at 8:07 PM, Andres Gonzalez w=
rote:
> How do I call PHP code that will run server side, from javascript code th=
at
> is running client side?
>
> I have a lot of PHP server side code written and working within CodeIgnit=
er.
> =A0Now, my project
> has changed and (for reasons unimportant to this discussion) we are now N=
OT
> going to
> use apache and CodeIgniter, but instead, we are going to have to use an h=
ttp
> server that does
> not support PHP internally. =A0But I want to reuse my original PHP code. =
So I
> am thinking that I
> can execute the PHP code via a command line interface using the PHP cli
> interface instead of
> the PHP cgi interface. But, I will have to initiate this serversid call v=
ia
> javascript code running
> on the client.
>
> I know...kind of convoluted. But how would one do this if necessary?
>
> -Andres
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: PHP and javascript

am 20.01.2010 07:08:41 von Rene Veerman

oh, and if you're going to use ajax->non-phphttpd->php->andback, then
check if your dear non-php httpd abuses the CPU while waiting for PHP
to return the results...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php