top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Reading . or .. using fread/fopen never ends on PHP?

+3 votes
281 views

Discovered today: fopen() opens '.' and '..' but fread() returns nothing without errors nor end-of-file, so this loop:

 $f = fopen('.', 'r');
 if( $f === FALSE ) die("fopen failed");
 $n = 0;
 while(($s = fread($f, 10)) !== FALSE)
 $n += strlen($s);
 fclose($f);
 echo "total bytes read: $nn";

never ends! The same happens with '..'. Tested on PHP 5.6.3 and 7.0.0 under Slackware 14.1 32-bits. Under Vista, instead, fopen() fails as expected.

Bug or specific feature under Linux?

posted Mar 2, 2015 by Amit Mishra

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+1 vote

We have a service where we have a front end using Wordpress/Magento/custom PHP code and a distributed backend using various other servers and services from note.js, magento, mysql, c#, java, ms sqlserver, Apache, etc.

The idea is we want to have multiple UIs spread across different geographies (different USA states, different countries, etc.) either user selectable or load-balancer assigned

How can we have it set up such that someone's login/authentication is valid across the different UIs (and can switch amongst them) without re-logging in when they switch (after having logged in already to any of the nodes). I don't want to have to constantly authenticate against some shared backend for every request either, so I imagine some kind of token must be used? Like how does OpenID work? Or these "Login with Facebook" or "Google ID"? Amazon AWS/EC2 are good examples for their UI console to manage computes as it has different regions at the top you switch to simply by the dropdown and really nothing else changes except some AJAX reload of your statistics, even the URL is mostly the same except another parameter.

We're not necessarily married to Wordpress and in fact we're trying to phase it out eventually and only use Magento.

Custom code is also an option - at least if there is a good example base or API we can maybe hack it in.

We're open to many technologies, but obviously would prefer to use one we already have (PHP ideally)

Any pointer will be helpful?

0 votes

I have a page where the user can select a few products, then I have a database PHP MySQL query that selects recent purchases of those products and also where they were purchased from like:

- query... select widget1 - widget2 and widget3

RESULT...

widget1, invoice 51, sold from store 1
widget1, invoice 72, sold from store 2
widget1, invoice 59, sold from store 1

widget2, invoice 2, sold from store 2
widget2, invoice 81, sold from store 1

widget3, invoice 201, sold from store 1
widget3, invoice 151, sold from store 2
widget3, invoice 17, sold from store 2
widget3, invoice 3, sold from store 1

I would like to generate report that can do some summary functions, so that the output report looks something like:

'SHOW PRODUCTS with STORE SUMMARY'

STORE 1

widget1, invoice 51, more fields here
widget1, invoice 59, more fields here
widget2, invoice 81, more fields here
widget3, invoice 201, more fields here
widget3, invoice 3, more fields here

STORE 2

widget1, invoice 72, more fields here
widget2, invoice 2, more fields here
widget3, invoice 151, more fields here
widget3, invoice 17, more fields here

I am curious how to construct the php to be able to simulate this 'STORE SUMMARY' on the report page. Any ideas are welcome.

+1 vote

I wish to align my output.

An example-

fprintf($fptr1, "%st %stn", $row1[0],$row1[1]);

In each row of output if the strings are wider than the tab setting, the text will indent.

Is there anyway I can formulate the fprinf so that each string will print at a specific place?

...