Local cURL in PHP: what route is used? - php

Suppose server A, via domain A, hosts a website.
Suppose server A, via domain B, also hosts a web service.
The website calls this web service via a PHP/cURL-based API.
Question: even though they live on the same physical server, am I right in thinking the request goes out to the ether and back in, because the domains are different, or does cURL/something have some way of "knowing" it's really the same server, and so there's no reason to go outside?

As far as I know, the request leaves the server no matter what since it's over http - there's no way of it knowing weather the two resources are on the same server or not. You could rip through all the source code but I don't think it would do that - usually if you want to call a resource on the same server you can use absolute file paths as opposed to http requests.
curl source:
curl source

Related

Access files in remote computer with php

I need to create an application using php which is hosted in a server and need to communicate with a csv file located in clients local machine. Is there any way we could do this ? How can I connect to a remote csv file ? Is this possible ?
Server machine accessing a csv file directly from a client machine is not a good idea. It's a security threat indeed. Consider you are navigating some website and it's server is able to access your computer's file system!!!
There are various alternatives to achieve this, some of these might be:
Make the user upload csv files to server in order to make it
available to the server application
If the client and server are in the same network, then share the
folder on client machine to make it accessible from the server
etc... I would have preferred the first option as mentioned above.
As #AnthonyB mentioned in comment under your question, server can't directly call client, and that is true. Server is called "server" as it serves requests from the client.
To be able to give away files to remote requests, your client needs its own server application, like Apache HTTPD for example.
In case if you need continuously request client's server to collect files with your PHP server, what you are looking for called "worker". One of AWS tools called Elastic Beanstalk offers possibility to choose a server or a worker application during start up wizard for PHP. It is pretty straight forward and easy to use.
Please note, that your client must have dedicated IP address or use Dynamic DNS approach by pushing its IP to a DB (or directly to a server) where worker will take it from.
If you don't need dedicated worker, you can configure CRON JOB to send requests to clients server applications.
IMHO, all that scenario worth it only if you are building corporate grade application. In most cases (and if you do REALLY need to collect files from clients) you have to install Apache + PHP server on the client side and make this guys to wait for request from YOUR remote php server. Without it, you can not get files from clients computers via browser without user input interactions. At least legally :)

Server returning 501 error, on file upload, when using nginx redirect

I have a multi-server architecture i.e Server a and server b, Now I want all the URL's hit containg a perticuler keyword should always go to server a, So I added a nginx rule (if url have keyword redirect to server a)
Now every thing is working fine but file upload is returning error code 501, But the issue resolves if I make an entry for server a IP in my /etc/hosts.
Using Angular and php
Ok So finally I found the issue. It was happening because of the options request.
Options is a special kind of request which is used when the client wants to determine other available methods to retrieve or process a document on the Web server.
So in my case my web server a and b have options method implemented while the server c (which is acting as a load balancer) does not resulting in 501 not implemented error

Redirect Piwik HTTP request to different server

I have Piwik running on one server, Server A. All my websites run on a different server, Server B. I don't want my users to know Server A's address (including any cookies that would be set), but I want it to do all the statistics. I presume I will have to redirect all the requests to piwik.php from Server B to Server A but I don't know how.
## Piwik Proxy Hide URL
This script allows to track statistics using Piwik, without revealing the
Piwik Server URL. This is useful for users who track multiple websites
on the same Piwik server, but don't want to show the Piwik server URL in
the source code of all tracked websites.
Located in the /path/to/piwik/misc/proxy-hide-piwik-url/ folder.
Should do what your looking for.

Using PHP how to pass variables securely between scripts on different servers

I have a login form on one server, server A. Hosted on another server, server B, I have a script to check the data and return the result. Server B sends the result to server A, but I don't want to pass the result back in the URL or headers with various redirects, because people can spoof a "true/false" to change the result of the login.
e.g.
I can't use HTTPS/SSL as my web host does not support it for free.
You could set up an ssh tunnel between the servers and have the web server on B listen only on localhost:Bs_tunnel_port, while A connects to its localhost:As_tunnel_port.
Or get that SSL thing going... ;)

What does PHP do when calling a URL located on the same Apache server?

I have two PHP applications on the same Apache server. At some point, application A needs to call a URL on application B.
So let's say a script located at http://somedomain.com/app1/action need to download http://somedomain.com/app2/action using file_get_contents() (the domain is the same for both applications)
I was wondering how does PHP handle this? Is the request going through the whole internet, as if it was a call to an external URL? Or is it somehow optimizing it and accessing the application on the server directly?
I think it depends from your DNS resolution and is not related to PHP.
If your network is properly configured, you should be able to access the site on your local network even by calling the public url.
To be sure about your request not leaving the server, you could use the localhost ( or 127.0.0.1 ) address. You can also use the local ip address to access it over the local network.
It uses the whole TCP/IP stack of the operating system, if that's what you want to know.
If it's in the same server, it wouldn't have to resolve the DNS name if you use 127.0.0.1 instead of somedomainname.com.
Usually request do not "go out" of your server, so application B is accessed quicly by application A.
Requests can "go out" in the wild and then being routed back to your server (and that's not so good for performance) if your server DNS are not configured well (pratically, your server can't recognize itself as somedomain.com).
The whole internet is big. But it would unlikely leave the server, depending on the network layout.
The request goes through every server between the source and the destination. Since they are the same, that is no servers.

Categories