1
Dear I have a framework that accesses data from other servers, I programmed the entire system on localhost, on my machine. However, when playing for the server the external page call does not work, for example:
require_once("http://meusite.com.br/pagina.php");
I have already allow_url_include = On and allow_url_fopen = On, but it doesn’t work.
Errors appear: Warning: require_once('http://meusite.com.br/pagina.php'): failed to open stream: Connection timed out in /var/www/pagina.php on line 231 Fatal error: require_once(): Failed Opening required 'http://meusite.com.br/pagina.php' (include_path='.: /usr/share/php:/usr/share/Pear') in /var/www/i9/page on line 231
Detail: Although I wanted to include pages from other servers, the server I refer to "meusite.com.br" is the server itself where the "page.php" is. Could that be the problem? That instead of using require_once through url, I am forced to user the way DIR?
Will I need to use file_gets_content()?
Timeout on production server.
– rray
Even file_gets_content() gives timeout, which will be, which variable should I set on the server?
– Maicon Herverton
Are you trying to include a page from within the same server? Or are you on another?
– KhaosDoctor
That’s inside the same server!
– Maicon Herverton
Try using this:
<?php
define('__ROOT__', dirname(dirname(__FILE__))); 
require_once(__ROOT__.'/config.php'); 
?>
– David Damasceno
@Is there any property that blocks this from making any kind of reference to the server itself? Because I gave a Url on an external site and it worked, and even from my localhost to the production server it responds with the pages. But when I threw it to himself it doesn’t work anymore.
– Maicon Herverton
There are many things that may be causing the problem, but none of them are related to your code or PHP configuration. The error message clearly indicates that the request failed by timeout, so there is something blocking the connection, just take a paper and pen and write all the route your server will have to do to connect correctly to this URL, the error will be in one of the points. The most common is that some firewall is blocking the connection, including, if you use Cloudflare in the domain reported in include, it is most likely the reason for the problem.
– Clayderson Ferreira
@Claydersonferreira I also think that’s the problem I’ll check.
– Maicon Herverton
Okay, and one more thing. If you don’t have a very reasonable reason to be using include via URL (since as you said, the file to be included is on the same server), it is best to use the conventional method per directory. The reason is very simple and obvious. But... however, if you set your server to respond to the domain internally (without having to solve the DNS), it already reduces the problem a little.
– Clayderson Ferreira
Guys, the problem now is that passing parameters in require_once (even using the local directory) gives error. "require_once(ROOT."/i9tax_new/teste.php? group=". $_GET['group']." &idUsuario=". $_SESSION['i9_usuario']);" Not allowed to pass parameters? Locally I managed to do this on a PHP server (XAMPP WINDOWS) but on the production server that is LINUX I cannot, some parameter to adjust?
– Maicon Herverton
Warning: require_once(/var/www/i9tax_new/teste.php?group=731db9563f89bd76f55f9619b61d3da4&idUsuario=400379d4eaa6ec24826dd44cd5cf65a3): failed to open stream: No such file or directory in /var/www/i9/principal.php on line 238 Fatal error: require_once(): Failed Opening required '/var/www/i9tax_new/teste.php? group=731db9563f89bd76f55f9619b61d3da4&idUsuario=400379d4eaa6ec24826dd44cd5cf65a3' (include_path='.:/usr/share/php:/usr/share/Pear') in /var/www/i9/principal.php on line 238
– Maicon Herverton
require_once
with parameters? Restructure your code so that testing.php only has functions/classes,require_once
in this file without parameter, and anywhere in your code call the functions/classes.– André LFS Bacci
Verdade @Andrélfsbacci great idea, thanks! I hadn’t thought about it, that tosco kk, is that I migrated a platform to another there many concepts I tried to maintain and I did not connect in the orientation to objects.
– Maicon Herverton
Thank you all, I did it! I will do the following: 1 - flag the platform modules to see if they are internal modules (from the server itself) or if they are third party server modules (other programmers other servers), if it is internal it uses the ROOT if it is external it uses require_once on the third party address server.
– Maicon Herverton
Guys, I have a similar problem, this time with regard to a page simulation ". html", I wanted to use the function to fetch the contents of the page file_get_contents("http://meusite.com.br/pagina.html") that is on my own server, but I don’t want only the code of the page I want it to be "processed by file_get_contents"that simulates the opening of the page by an external user, i.e., the "pegconteudo.php" page is on the same server as "pagina.html" and the same time_out error occurs.
– Maicon Herverton