when is php executed on apache2? - php

I am trying to figure out when exacly are php scripts interpreted on apache server via mod_php in connection lifetime(tcp session lifetime).

PHP scripts are executed by Apache in response to HTTP requests. A HTTP request requires a fully established TCP connection.

Related

Can i use Node js, Websocket and php in the same apache server?

I was wondering if its possible create a website combined with NodeJs, Websocket and php in the same Apache server. Is there any documentation that can i read?
"In the same Apache server", No. node.js does not run in Apache. It runs by itself.
But, you can use multiple technologies on the same server. For starters, you could have two completely separate web servers running on separate ports, one that was Apache + PHP + webSocket and another that was node.js + webSocket.
But, node.js does not use Apache. Instead, node.js would typically be configured to be it's own web server all by itself. So, you don't typically run an Apache server and have some requests through it go to PHP and some go to node.js.
Using PHP and node.js together depends entirely upon what you're trying to do with them. You could have your web server as a node.js server and then have some requests that node.js receives actually execute some PHP and get the results from running a PHP script. And, you could do the reverse too with a PHP script fielding the request and then manually running a node.js script for some requests.
To answer any more fully, we need to know what you're really trying to do with PHP, node.js and webSockets.
FYI, you could set up an NGINX proxy on port 80 and configure it to direct some requests to your Apache/PHP server (running on a different port) and other requests to your node.js server (running on a different port). Incoming webSocket requests would then be directed to one of the two servers.

How to access php session data within a HHVM process using C++?

Here is some background info:
I have a dynamic loaded extension running on HHVM using FastCGI
I have a login'ed session ready. e.g. example.com/login.php
I have my own TCP server running within the HHVM fastCGI process, listening port e.g. 8080.
(Assuming the TCP server is started when the extension is loaded, and wait for web socket connections)
What I want to do is, to re-use the session started by login.php in my own TCP server that serves web socket connections. The client should already give me the PHPSESSID cookie from the HTTP header, all I think I need to do is to use that ID to lookup somewhere in the HHVM runtime (because we're in the same process), checking if that session exist or something like that. So I can safely stream data to that websocket.
Is there an API I can call to do that?
Is there any example I can follow? Can someone help me please?
Thank you,

Persistant TCP Connection To Speed Up Remote File Fetching

I have a PHP script that uses file_get_contents to fetch a file on a remote server on every page load. Is it possible to make a persistent connection between the two servers to speed up the time it takes to fetch this file?
Your PHP process is likely ending each request, so you will have to handle this outside of the main PHP process.
I would recommend setting up Nginx as a proxy, and pointing your PHP script at Nginx. You can then configure Nginx to use HTTP/1.1 keep-alive, which will keep a persistent connection open if requests are coming through regularly.

Does Wamp server handle mutiple HTTP connections?

I am creating an application on the phone that queries to the server. The server side scripting is done in PHP. Do i have to create threads to handle multiple http requests or does wamp provide for it. How does Wamp handle multiple HTTP requests?
WAMP runs an instance of Apache. Apache can handle many HTTP requests. Your web application determines how those requests are handled.
Apache does that for you. That's the point of having a HTTP Server (serving multiple clients).

How does the Apache httpd webserver communicate with Perl or PHP or CGI and gets the output and returns the response?

From the client browser to the Apache httpd webserver there is a clear defined protocol, HTTP, via TCP/IP (sockets). I'm having hard time to understand what channel/protocol is used from the Apache httpd webserver to Perl or PHP or CGI? Is it Inter-Process Communication via sockets or pipse or message queue or signals? Could someone shed light on what is really going on behind the scene? Is it as if the Apache httpd webserver executes another program (Perl or PHP) and captures the output and then resends it to client browser?
From Linux Server Security:
The CGI protocol doesn't specify how the web server should communicate with the CGI program. There have been two main solutions:
Standalone CGI programs
Apache receives a CGI request, opens a two-way pipe to an external program, sends it the CGI input data, and returns the program's output to the client. As a separate process, the program can crash without bringing down the web server. The down side is that it's relatively slow to start a new process.
Built-in CGI programs
The program is rewritten as an Apache module and incurs its startup cost only when an Apache process starts. This is much faster than an external program and has access to Apache's internals and other modules. The most popular modules for CGI in Apache are the interpreter engines for Perl (mod_perl) and PHP (mod_php).
Communication with CGI programs is done via two channels: simple IO redirection (that is, STDIN and STDOUT) and environment variables.
The HTTP server sends the request to the CGI's STDIN. It reads the HTTP response from the CGI's STDOUT and sends it (slightly modified) to the client browser. Additional server data (like the request size or some server parameters) are set to environment parameters that usually start with HTTP_.

Categories