By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

funny problem

P: n/a
Hi,
(1) I have about 8-9 .php files which are far from complex. I first
used GET in all of them. Worked fine. Then I changed all method="get"
to method="post" and $_GET to $_POST with search-replace, thinking that
it should work, but, it seems the $_POST variables are not getting
populated. Then I tried a simple one-page script using post - works
fine. So what could be the problem? I am not using
import_request_variables() or any such advanced feature.
(2) How do you address the situation where you have several
simultaneous users of your web application and your script reads from
the same single file, and maybe writes to the same single file(keep
aside the case of poor design, I am talking of say a page hit counter,
or reading initial settings from the single file), will not several
copies of your code in memory reading the same file on disk cause
problems? is there some specific code for such a situation? I looked
for "threadsafe" and "multiple user" but could not get anything.

Any help is appreciated.
Joseph S.

Oct 27 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joseph S. napisa³(a):
Hi,
(1) I have about 8-9 .php files which are far from complex. I first
used GET in all of them. Worked fine. Then I changed all method="get"
to method="post" and $_GET to $_POST with search-replace, thinking that
it should work, but, it seems the $_POST variables are not getting
populated. Then I tried a simple one-page script using post - works
fine. So what could be the problem? I am not using
import_request_variables() or any such advanced feature.


Maybe you using something like:

echo "<a href=\"index?a=$a\">text</a>";

This is works only with $_GET.

Tom Wysocki
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDYTbOLaRVEfZTNaERAs59AJ9lWhreocKG3wTuUdqFIJ zObB0bFACcCu8D
IHtXYxGa5wywG5GH0aB2LV4=
=UOBG
-----END PGP SIGNATURE-----
Oct 27 '05 #2

P: n/a
Joseph S. wrote:
Hi,
(1) I have about 8-9 .php files which are far from complex. I first
used GET in all of them. Worked fine. Then I changed all method="get"
to method="post" and $_GET to $_POST with search-replace, thinking that
it should work, but, it seems the $_POST variables are not getting
populated. Then I tried a simple one-page script using post - works
fine. So what could be the problem? I am not using
import_request_variables() or any such advanced feature.
Do you submit the forms or do you build up a query portion of a URL? The
post method needs a <FORM> tag with form elements. It should be
submitted. With the get method, you can just call a URL with a query
portion.
(2) How do you address the situation where you have several
simultaneous users of your web application and your script reads from
the same single file, and maybe writes to the same single file(keep
aside the case of poor design, I am talking of say a page hit counter,
or reading initial settings from the single file), will not several
copies of your code in memory reading the same file on disk cause
problems? is there some specific code for such a situation? I looked
for "threadsafe" and "multiple user" but could not get anything.

Any help is appreciated.
Joseph S.

There are database servers that have addressed the locking and
multi-user problems for you and there are also free webcounters
available on the web. But if you want to do it with a file, you could
try to achieve a file lock. Depending on the OS, you could either
directly lock the file or work with a separate lockfile. Both have the
disadvantage that if anything goes wrong, the counter file remains
locked until you unlock it by hand.
An alternative approach is to run an external application (by using COM
on Windows, for example) that is the only process to touch the file.
Your PHP scripts can then call the external application for both reading
and writing.

Best regards
Oct 27 '05 #3

P: n/a
NC
Joseph S. wrote:

(1) I have about 8-9 .php files which are far from complex. I first
used GET in all of them. Worked fine. Then I changed all method="get"
to method="post" and $_GET to $_POST with search-replace, thinking that
it should work, but, it seems the $_POST variables are not getting
populated. Then I tried a simple one-page script using post - works
fine. So what could be the problem?
Some typo somewhere... Say, you now have $POST or $_POTS instead of
$_POST...
(2) How do you address the situation where you have several
simultaneous users of your web application and your script reads from
the same single file, and maybe writes to the same single file
Reading from the same file on a modern operating system should
require no attention at all; it is handled on the OS level.
Writing... well, read up on flock() and see what the manual has
to say about OS-specific details...

http://www.php.net/flock
I looked for "threadsafe" and "multiple user" but could not get
anything.


Thread is a Windows-only concept. On Unix, there are no threads,
only full-blown processes, each with a distinct ID... This is
why file locking would work on Unix, but not on Windows...

Cheers,
NC

Oct 27 '05 #4

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joseph S. wrote:
(2) How do you address the situation where you have several
simultaneous users of your web application and your script reads from
the same single file, and maybe writes to the same single file


Seems like the same old reader-writer concurrency problem. Use some method
to lock the files, in order to avoid multiple writes. See php.net/flock .

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Los verdaderos programadores no trabajan de 9 a 6. Si puede verse alguno a
las 9, es porque ha estado toda la noche trabajando.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDYTtP3jcQ2mg3Pc8RAjzpAKCIAnoVaMG/4ts3A20nacU4+Y9HzgCcCuM+
OkDdOCk0seC5EJ06bg1ioyI=
=tZN0
-----END PGP SIGNATURE-----
Oct 27 '05 #5

P: n/a
Why not use $_REQUEST?

Oct 28 '05 #6

P: n/a
Hi,
It was not typos or urls with "name.php?q=whatever", it was the form
tag attribute enctype="text/plain" -
it was inserted by default in the form tag that is generated by
PHPEclipse
when you select the form option for post from the popup dropdown:

<form action="link" method="post" enctype="text/plain">
cursor
</form>

It does not work with POST but works with GET.
(which is why the fact that it is part of the default text for the form
post tag in PHPEclipse comes as a surprise - it does not work - I have
XAMPP installed Apache/2.0.54 PHP/5.0.4 )

What I found is that with post, the enctype attribute
must either be omitted completely:
<form action="myform.php" method="post">
</form>
or,
if specified, must be set to
enctype="application/x-www-form-urlencoded" or
enctype="mulitpart/form-data"
which work.

As for concurrent file access, as Dikkie pointed out,
it is better to use a database
and if only read is involved, the OS should takes care of it.

I read php.net/flock and it seems better to use a database, however
small.

Thanks all,
Regards,
Joseph.

Oct 28 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.