Welcome! Log In Create A New Profile

Advanced

[PHP] No such file... but there is!

Posted by Jennifer 
Jennifer
[PHP] No such file... but there is!
November 28, 2017 04:30PM
Hi!

I'm having an intermittent problem with a script locating a text file. Here's the code section:


function is_crawler($agent) {
global $path;
$bots_file = $path;
$spiders = file($bots_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

foreach ($spiders as $spider) {
if (stristr($agent, $spider)) {
return true;
}
}
}

The error log shows these lines:

[28-Nov-2017 06:50:03] PHP Warning: file(.../counter/bots.txt): failed to open stream: No such file or directory in /home/.../counter/page_hit_counter.php on line 235
[28-Nov-2017 06:50:03] PHP Warning: Invalid argument supplied for foreach() in /home/.../counter/page_hit_counter.php on line 238


The bots file is there and is populated, so I'm not sure why this happens from time to time. It's not read by any other script, so I don't think it's a locking issue(?).

What could be causing this issue?

Thank you,
Jenni
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
Re: [PHP] No such file... but there is!
November 28, 2017 04:40PM
On Tue, Nov 28, 2017 at 10:22 AM, Jennifer <[email protected]>
wrote:

> Hi!
>
> I'm having an intermittent problem with a script locating a text
> file. Here's the code section:
>
>
> function is_crawler($agent) {
> global $path;
> $bots_file = $path;
> $spiders = file($bots_file, FILE_IGNORE_NEW_LINES |
> FILE_SKIP_EMPTY_LINES);
>
> foreach ($spiders as $spider) {
> if (stristr($agent, $spider)) {
> return true;
> }
> }
> }
>
> The error log shows these lines:
>
> [28-Nov-2017 06:50:03] PHP Warning: file(.../counter/bots.txt): failed to
> open stream: No such file or directory in /home/.../counter/page_hit_counter.php
> on line 235
> [28-Nov-2017 06:50:03] PHP Warning: Invalid argument supplied for
> foreach() in /home/.../counter/page_hit_counter.php on line 238
>
>
> The bots file is there and is populated, so I'm not sure why this
> happens from time to time. It's not read by any other script, so I don't
> think it's a locking issue(?).
>
> What could be causing this issue?
>
> Thank you,
> Jenni
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Use the absolute file location instead of the relative one.
Balbuena, Josue
RE: [PHP] No such file... but there is!
November 28, 2017 04:50PM
Have you checked the read privileges, sometimes the user that the web server is running doesn't let reading the file.

-----Original Message-----
From: Aziz Saleh [mailto:[email protected]]
Sent: martes, 28 de noviembre de 2017 09:34 a. m.
To: Jennifer <[email protected]>
Cc: PHP General <[email protected]>
Subject: Re: [PHP] No such file... but there is!

On Tue, Nov 28, 2017 at 10:22 AM, Jennifer <[email protected]>
wrote:

> Hi!
>
> I'm having an intermittent problem with a script locating a text
> file. Here's the code section:
>
>
> function is_crawler($agent) {
> global $path;
> $bots_file = $path;
> $spiders = file($bots_file, FILE_IGNORE_NEW_LINES |
> FILE_SKIP_EMPTY_LINES);
>
> foreach ($spiders as $spider) {
> if (stristr($agent, $spider)) {
> return true;
> }
> }
> }
>
> The error log shows these lines:
>
> [28-Nov-2017 06:50:03] PHP Warning: file(.../counter/bots.txt): failed to
> open stream: No such file or directory in /home/.../counter/page_hit_counter.php
> on line 235
> [28-Nov-2017 06:50:03] PHP Warning: Invalid argument supplied for
> foreach() in /home/.../counter/page_hit_counter.php on line 238
>
>
> The bots file is there and is populated, so I'm not sure why this
> happens from time to time. It's not read by any other script, so I don't
> think it's a locking issue(?).
>
> What could be causing this issue?
>
> Thank you,
> Jenni
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Use the absolute file location instead of the relative one.
Jennifer
Re: [PHP] No such file... but there is!
November 28, 2017 05:00PM
> On Nov 28, 2017, at 7:39 AM, Jasper Kips <[email protected]> wrote:
>
> The problem lies in age path, which is, according to the log …./counter/bots.txt

Sorry. In those log entries, I replaced the full path with those dots. They are not in the code.

> Have you checked the read privileges


Yes. The privileges are correct.

> Use the absolute file location instead of the relative one.

I'm using the full, absolute path. However, since the file is in the same folder as the script, maybe I can get away with just the file name.

Again, this is an intermittent problem. It happens rarely, so that's why it's a mystery.

Thanks.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
Re: [PHP] No such file... but there is!
November 28, 2017 05:10PM
On Tue, Nov 28, 2017 at 10:53 AM, Jennifer <[email protected]>
wrote:

> > On Nov 28, 2017, at 7:39 AM, Jasper Kips <[email protected]> wrote:
> >
> > The problem lies in age path, which is, according to the log
> …./counter/bots.txt
>
> Sorry. In those log entries, I replaced the full path with those
> dots. They are not in the code.
>
> > Have you checked the read privileges
>
>
> Yes. The privileges are correct.
>
> > Use the absolute file location instead of the relative one.
>
> I'm using the full, absolute path. However, since the file is in
> the same folder as the script, maybe I can get away with just the file name.
>
> Again, this is an intermittent problem. It happens rarely, so
> that's why it's a mystery.
>
> Thanks.
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
file(.../counter/bots.txt)

tells me that you are using the relative and not absolute path. The only
reason I recommend using the absolute path is that the error would show any
issues, if any that are occurring and from where.

Another choice is to debug the location where the error is happening, I
have a feeling that it is coming from a location that you are not expecting..
Ashley Sheridan
Re: [PHP] No such file... but there is!
November 28, 2017 09:50PM
On 28 November 2017 15:58:27 GMT+00:00, Aziz Saleh <[email protected]> wrote:
>On Tue, Nov 28, 2017 at 10:53 AM, Jennifer
><[email protected]>
>wrote:
>
>> > On Nov 28, 2017, at 7:39 AM, Jasper Kips <[email protected]>
>wrote:
>> >
>> > The problem lies in age path, which is, according to the log
>> …./counter/bots.txt
>>
>> Sorry. In those log entries, I replaced the full path with
>those
>> dots. They are not in the code.
>>
>> > Have you checked the read privileges
>>
>>
>> Yes. The privileges are correct.
>>
>> > Use the absolute file location instead of the relative one.
>>
>> I'm using the full, absolute path. However, since the file
>is in
>> the same folder as the script, maybe I can get away with just the
>file name.
>>
>> Again, this is an intermittent problem. It happens rarely,
>so
>> that's why it's a mystery.
>>
>> Thanks.
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>file(.../counter/bots.txt)
>
>tells me that you are using the relative and not absolute path. The
>only
>reason I recommend using the absolute path is that the error would show
>any
>issues, if any that are occurring and from where.
>
>Another choice is to debug the location where the error is happening, I
>have a feeling that it is coming from a location that you are not
>expecting.

If it's intermittent, it could be that the file is locked when you try to open it, a problem with trying to open a shared file when the scripts hitting it could be open at the same time. You could try putting that logic into a database, which is built to handle this sort of concurrent access.
Thanks,
Ash

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Carsten Jensen
Re: [PHP] No such file... but there is!
November 29, 2017 09:40AM
Den 28-11-2017 kl. 16:34 skrev Aziz Saleh:
> On Tue, Nov 28, 2017 at 10:22 AM, Jennifer <[email protected]>
> wrote:
>
>> Hi!
>>
>> I'm having an intermittent problem with a script locating a text
>> file. Here's the code section:
>>
>>
>> function is_crawler($agent) {
>> global $path;
>> $bots_file = $path;
>> $spiders = file($bots_file, FILE_IGNORE_NEW_LINES |
>> FILE_SKIP_EMPTY_LINES);
>>
>> foreach ($spiders as $spider) {
>> if (stristr($agent, $spider)) {
>> return true;
>> }
>> }
>> }
>>
>> The error log shows these lines:
>>
>> [28-Nov-2017 06:50:03] PHP Warning: file(.../counter/bots.txt): failed to
>> open stream: No such file or directory in /home/.../counter/page_hit_counter.php
>> on line 235
>> [28-Nov-2017 06:50:03] PHP Warning: Invalid argument supplied for
>> foreach() in /home/.../counter/page_hit_counter.php on line 238
>>
>>
>> The bots file is there and is populated, so I'm not sure why this
>> happens from time to time. It's not read by any other script, so I don't
>> think it's a locking issue(?).
>>
>> What could be causing this issue?
>>
>> Thank you,
>> Jenni
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> Use the absolute file location instead of the relative one.
>
..../  looks wrong.

it should be ../ (2 dots)

or if you want to go parent 2 times ../../




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login