require file doesn't exist until refresh - php

I have a require line in my php script.
require_once('../main.inc.php');
every once in a while, when I load a page, I get a message 'failed to open stream. no such file or directory'
But when I hit refresh, the page loads just fine.
What might be happening that the script can't seem to find the file until I simply refresh?
I am really hitting the error at this point before I use the require/include
if(!file_exists('../main.inc.php')) die('Fatal error

try
include('../main.inc.php');

Related

php include only if HTTP request succeeds

Hi,
I have this code:
ob_start();
include( "https://example.net/news.php" );
$data = ob_get_contents();
ob_end_clean();
problem is that sometimes the request seems to fail for some reason (despite the requested file and the file that makes the request are on the same server) and then the page wont finish loading which is putting a lot of load on the server. This is the error I get:
PHP Warning: include(): Failed opening 'https://example.net/news.php' for inclusion
So I was thinking to condition the include only if the request succeeds so I wont have this problem. How can I do that?
Thank you.

How to trigger download failed error in php

On my site, i allow users to download videos, images (in chunks though), however, i want to make it in such a way that if a url parameter is not met, my download script should halt and cause download failed.
I did this:
<?php if(!$condition){
trigger_error('Fatal error occured', E_USER_ERROR);
}?>
The problem is that, the file downloaded( although, currupted), when i checked into the downloaded file in a notepad, i saw my fatal error ("Fatal error occured").
How do i stop the file from downloading at all?
Just put
exit();
inside the if, after you've triggered the error. This will halt the script execution so that any headers, content etc associated with the file does not get output.
Optionally you could also set an appropriate HTTP status code for the response.

PHP ftp_delete() generates warning "Command okay"

I can not find any answer to this as most problems revolve around a file not existing or a delete process not working.
I have an FTP device where I generate a file with an PHP script. After that, I try to FTP in, get the file and after that, delete it.
This all works fine, I can connect, get the file and save it locally and then delete it. Except for one thing, the ftp_delete() function results in a warning.
PHP gives me the following, when executing the script:
A PHP Error was encountered
Severity: Warning
Message: ftp_delete(): Command okay
I looked up the error code, it means it was successful. And it was because the file is deleted on the FTP device.
So why does this generate an PHP error?
Cheers.
The RFC 959 (FTP specification) mandates that on a successful completion of the DELE command, the server should respond with 250 status code.
The PHP FTP implementation is very strict, yielding a warning on any other code, even if it indicates a success (2xx class).
Your server probably uses some other 2xx code, like a generic 200 Command okay.

Laravel can't find some files

I'm in the middle of some work and suddenly I get this.
Warning: require(/opt/lampp/htdocs/ERP/laravel/÷5 ication)
[function.require]: failed to open stream: No such file or directory
in /opt/lampp/htdocs/ERP/public/index.php on line 34
Fatal error: require() [function.require]: Failed opening required
'/opt/lampp/htdocs/ERP/laravel/÷5 ication'
(include_path='.:/opt/lampp/lib/php') in
/opt/lampp/htdocs/ERP/public/index.php on line 34
This error is shown on some requests that have no relation, so there is not a problem with them. This problem started showing a few hours ago
I have checked the files mentioned on the message and they are OK, based on the download I just made to make sure.
If I keep refreshing the page the file name changes. If I insist, it will end up loading my page. This process is costing me a lot of time, I'm trying to make some tests and sometimes this message shows up.
Well...you said that it happens in same pages that make requests, take a good look on your requests and try looking for something wrong.
A good tip is to use the Profile on your framework configuration. You will have a bottom bar with details about the queries executed and logs created.
I think that will help you find the problem.

Zend session_start gives Fatal error: Exception thrown without a stack frame in Unknown on line 0

When running a Zend application locally I get Fatal error: Exception thrown without a stack frame in Unknown on line 0, i traced that error to a line $startedCleanly = session_start();
I can't get through it, when I restart the server and reload the page I do not get the error, but on every other reload I get it, I looked into a php/tmp dir too see if there are any files, and as I see they aren't there. I think that session isn't written but when I try just a simple test.php file with session_start(); line, without zend framework, I see that there is a file created in that dir.
I really don't know where to go next.
Happens when your destructor or error handler throws an exception. That can happen for multiple reasons depending on your exact setup and method for session storage you're using. For example the session directory is not writeable or does not exist, database is not accessible or fields are invalid, redis does not respond, etc.
So, check your settings and look for something that would prevent saving the session data.
More elaborate description can be found here.
I know this post is old, but I've just figured out that I was getting "Fatal error: Exception thrown without a stack frame in Unknown on line 0" because my 'modified' and 'lifetime' columns were of type 'timestamp without time zone' when they should have been 'integer' (I'm using Postgres 9 BTW)
Hope this helps someone.
The problem could also be a disk full problem !!!

Categories