Re: [PHP] Re: File or directory?

2009-08-18 Thread Ollisso

On Tue, 18 Aug 2009 13:00:37 +0300, Clancy clanc...@cybec.com.au wrote:

On Sun, 16 Aug 2009 23:24:05 -0600, george.lang...@shaw.ca (George  
Langley) wrote:



is_dir()

http://ca3.php.net/is_dir

is_file()

http://ca3.php.net/manual/en/function.is-file.php

I specifically asked about FTP under PHP.  As far as I can see neither  
of these references

have anything to do with FTP.



http://ca3.php.net/manual/en/wrappers.ftp.php

Supports stat()	No	As of PHP 5.0.0: filesize(), filetype(), file_exists(),  
is_file(), and is_dir() elements only. As of PHP 5.1.0: filemtime().


should work if PHP = 5.0.0

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Issue with the huge import script

2009-08-16 Thread Ollisso
On Sun, 16 Aug 2009 04:15:12 +0300, Devendra Jadhav  
devendra...@gmail.com wrote:



Is it because of the size of the records or something else...?

Please suggest me some solution which is faster, safe and easy to code :D



What about using insert ignore ? :)

1. add UNIQUE constraint on a key you want to add, so you won't be able to  
add row with same ID twice.

2. then use INSERT IGNORE into 

= easy to code, easy to use.

Of course, this aproach won't work if database will grow larger and  
larger. (if you adding  new rows all the time)


Then it is better to use this aproach:

1. add auto_increment column to original table.
2. before getting new rows from old table, check what is maximum ID from  
new table.
3. get only rows where old_table.id  new_table.max_id remember to ORDER  
BY ID ASC.




--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Synchronizing autonumber fields

2009-08-11 Thread Ollisso
On Tue, 11 Aug 2009 10:04:52 +0300, Leidago !Noabeb  
leid...@googlemail.com wrote:



Hi

I have the following tables setup in MYSQL:

Region 1 Region 2
HQ
Tbl1 with autonumbered (PK) Tbl1 with autonumbered (PK)
Tbl1 autonumbered-PK

To explain the above. Basically there are two regions that collect
information and then at the end of each month they have to send the
information to HQ. This is fine, but the problem comes when the
information (the data in the tables) is submitted to HQ. All three
tables have the same names and the same structure. We want to
synchronize the information sent by the regions into one table at HQ.
How can we do this without having the duplicate number problem?

Thanks


You can change system, so it will increment not by one, but by 2:

then Region 1 with have numbers:
1, 3 ,5 , 7 , etc
Region 2: 2, 4 ,6, 8 etc

then they are going to be easily mixed together.
As a bonus - it will be easy to see from where this record came.

Only problem - you can do it only on server level, not table level
http://forums.mysql.com/read.php?10,269379,269436#msg-269436


--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Class Problems

2009-08-11 Thread Ollisso
On Tue, 11 Aug 2009 18:35:35 +0300, Ashley Sheridan  
a...@ashleysheridan.co.uk wrote:



Hey all,

Is there any reason why this shouldn't work correctly on a server
running PHP 4.4.7:

?php
class testClass
{
private $foo = 'bar';
}

print 'wtf';
?

I would at the very least expect to see the 'wtf' printed out. I've got
a whole class I've written that works fine in PHP 5, but on PHP 4
server, it does nothing with even this simple example.

Any ideas?


PHP4 does not support  classes that much.
Especially private/public keywords.

PS: you should enable display_errors and set error_reporting(E_ALL), then  
you will see error here.





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: MySQL auto_increment fields Server version: 5.1.32-community-log

2009-08-10 Thread Ollisso
On Sun, 09 Aug 2009 21:17:15 +0300, Ralph Deffke ralph_def...@yahoo.de  
wrote:



Hi all,

I'm facing the fact that it seems that auto_increment fields in a table  
not
start at 1 like it was in earlier versions even if I install mySQL brand  
new

creating all tables new. it seems to me that auto_increments handling has
changed to older version. is somebody out there who can give me a quick
background about auto_increment and how and if I can control the  
behavior of

mySQL about them.

ralph_def...@yahoo.de



try:
ALTER TABLE xxx AUTO_INCREMENT=1;



--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Buffered Logging?

2009-08-07 Thread Ollisso

On Sat, 08 Aug 2009 01:46:38 +0300, Waynn Lue waynn...@gmail.com wrote:


Hey PHPers,

We've been doing sampled logging to the database in our application for
awhile, and now I'm hoping eventually to blow that out to a larger scale.
I'm worried about the performance implications of logging to our  
database on

...



If you are using mysql and MyISAM tables, you can try using insert  
DELAYED  method.


http://dev.mysql.com/doc/refman/5.1/en/insert-delayed.html

This will bulk all your inserts for writes.


--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] navigation include not functioning

2009-08-05 Thread ollisso
On Wed, 05 Aug 2009 20:19:00 +0300, Allen McCabe allenmcc...@gmail.com  
wrote:



Sure.

When I load my site, default.php loads ( displaying:
http://uplinkdesign.hostzi.com/ in the browser as expected). $thisPage is
set to about via:

?php
if (!isset($thisPage)) {
 $thisPage=about;
 } else {
 $thisPage = addslashes($_GET['page']);
 }
?

in the head tags.


I am seeing this:

The first 2 includes work just fine, loading to proper middle section and
proper right-hand-side page content, the navigation include also loads,  
but
all the of tabs (background images) are the currentpage image, as  
opposed

to not, as they should be (the the exception of the About Us background
image).

It seems that $thisPage is equal to all four values, so all the if
statements within navigation tell PHP to load the current page image for  
all

4 links.

Does this help?


Looks like you need something like that:
$pages  = array(
// list of modules you have, for example:
 'about' , 'help', etc
);
$page	= isset($_GET['page'])  isset($pages[$_GET['page']])	?   
$_GET['page'] : 'about';

// about is default page here

then just:
include 'modules/'.$page.'.php';

Always remember that you have to check what is included.
Best approach(if possible) to have a predefined list of all modules which  
can be included.


Else, there is some nasty things like:
?page=../index.php
(infinity recurssion)

?page=http://otherhost.com/hacker.
(inclusion of malicious script)
and so on.




On Wed, Aug 5, 2009 at 10:10 AM, Jerry Wilborn  
jerrywilb...@gmail.comwrote:



Look

I'm having trouble understanding your description of the problem.  Can  
you

tell us what you're seeing and what you expect to see?
Jerry Wilborn
jerrywilb...@gmail.com



On Wed, Aug 5, 2009 at 12:00 PM, Allen McCabe  
allenmcc...@gmail.comwrote:


I am trying to generate pages by importing content in includes, and  
using

my
navigation include to tell PHP to replace a $thisPage variable which  
all

the
includes use ?php include('phpincludes/' . $thisPage . '.php') ?

The idea behind it (I know tons of people do it, but I'm new to this
concept), is to have a 'layout' page where only a variable changes  
using
$_GET on an href (index.php?page=services or index.php?page=about) to  
load

the new 'pages'.

PROBLEM:
All my links are displaying the current page state, and links are not
building around the link text (hrefs are built conditionally with if
$thisPage != services then build the link, otherwise leave it as normal
text). Same thing with the background image behind the link text (to
indicate a page's current position). If the condition is not true, all  
the
links (except the true current 'page') are supposed reload index.php  
and

pass a variable to itself to place into $thisPage using
href=index.php?page= (after which I have a variable which stores  
about

or services within the if statement near the link text.

If this sounds like something you are familiar with (former issues and
whatnot) please let me know what I'm doing wrong. I would be happy to  
give
you any code you want to look at (index.php or navigation.php,  
whatever).


Thanks again for your help PHP gurus!











--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Time keeping in DB

2009-08-05 Thread Ollisso
On Wed, 05 Aug 2009 22:18:31 +0300, Shawn McKenzie nos...@mckenzies.net  
wrote:



So, obviously not PHP related, but I'm looking for thoughts on the best
way to record time sheets in a DB.  A time sheet for hours worked per
day, not like a time clock where you start and stop.

The two possibilities that I have thought of are (these are simplistic,
of course I'll be storing references to the user, the project code etc.):

1. One record for each 7 day week (year, week_num, d1, d2, d3, d4, d5,
d6, d7) where the dX field holds the hours worked
2. One record for each day (date, hours)



In simpliest scenarios, it is better to use first approach.
it is best in terms of simplicity, usage, space consumption.

in case if you need to store extra information about hours (at which  
location, at which time started, etc, ), then it might be better to split  
it to following tbles:


1. Time sheet.
All basic information about sheet: user, year, week number, etc. whatever  
you need.

Just add unique id of this timesheet
Here you can also add cached version of hours per day.

2. Day information:
timesheetId, dayId(1-7),  hours, a lot of extra fields for this day.

Of course, this is applicable only if you have a lot of extra information  
for each day.

If not, then use easiet approach.






--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Radio buttons problem

2009-08-03 Thread Ollisso
On Mon, 03 Aug 2009 11:01:13 +0300, leledumbo leledumbo_c...@yahoo.co.id  
wrote:





How can I make a radio button in one entry to behave independently from  
the

one in another so that it can be accessed as name and email above?


This should work:

input type='radio' name='sex[1]' value='1'
input type='radio' name='sex[1]' value='2'
input type='radio' name='sex[2]' value='1'
input type='radio' name='sex[2]' value='2'



--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Problem: Writing into Files?

2009-08-03 Thread Ollisso

On Sun, 02 Aug 2009 13:14:42 +0300, Parham Doustdar parha...@gmail.com
wrote:


Now this one always sets the file to one for some reason. I'll reiterate
just in case there's been a misunderstanding on my part:
[code]
$fp = fopen($f, r+);
while (!flock($fp, LOCK_EX))
sleep(1);
$count = fgets($fp,filesize($fp));
ftruncate($fp, 0);
fwrite($fp, ($count+1));
flock($fp, LOCK_UN);
fclose($fp);
Thanks a lot again for your help.



This will work:

$f  = 'file.txt';
$fp = fopen($f, r+);
while (!flock($fp, LOCK_EX))
sleep(1);
$count = intval(fread($fp,1024));
fseek($fp,0,SEEK_SET);
ftruncate($fp, 0);
fwrite($fp, ($count+1));
fclose($fp);

echo $count;

(first you should create file file.txt manually, only then it will work)

--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] isset not functioning

2009-08-03 Thread Ollisso
On Mon, 03 Aug 2009 20:11:44 +0300, Parham Doustdar parha...@gmail.com  
wrote:



Your if-statement should be like this:

[code]
if(isset($_REQUEST['firstname'])  !empty($_REQUEST['firstname'])) {
...
}
[/code]


Or even:

[code]
if(!empty($_REQUEST['firstname'])) {
 ...
}
[/code]

Because empty will also check if variable exists

--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP programming strategy

2009-08-03 Thread Ollisso

On Sun, 02 Aug 2009 04:25:40 +0300, Clancy clanc...@cybec.com.au wrote:

Is anyone here interested in discussing programming strategy, or or know  
of a discussion

group which is interested in the subject?

The sorts of questions I am interested in are:

1. I have a highly variable program which always shows the same page,  
but which includes
different modules to give different results.  The various modules call  
on different
functions. Is it better to minimise memory by including only the  
functions actually
required, but increase the number of files included, or to bundle all  
the functions into
one file, thereby reducing the number of files included but increasing  
the size in memory?


2. As PHP is an interpreted program comments certainly increase the  
memory requirements,
and presumably they slow down the operation of the program. Would  
stripping out the
comments before uploading the production version give any visible  
improvement in

performance?


I think, first question you should answer following questions:
1. How large is your workload ?
2. How it is easier to develop this program?
3. can you logically split functions to different modules ?
4. Did you used other methods of optimizations ?

This questions is important because:
1. if you don't have huge workload - this kind of optimization won't help  
you at all. just will take time needed for actual divelopment.


2. PHP Compiler are already fast enough. So if you don't have very  
high-load website, then it is more important how fast you write program,  
rather than how many files do you have.


3. If you can logically split them - then it is good to split them,  
because it will easier to develop them.

Mostly, I personally try to separate functions to a modules:
I have 2-3 files per action: skin file, and action file. Sometimes:  
datatype file (for functions related to information type, like Person)
Also I have like 10 library files: they have all functions related to this  
library: skins , person related, etc.


This is optimanl, because I can easily find whatever I need when  
developing.


4. If you have huge load, then it is much more efficient (and easier) to  
use other methods. For Example: install APC (http://fi2.php.net/apc )
It will cache all requests to your files and this will have huge impact on  
your performance. Much more than you can achieve by stripping comments on  
moving functions around. (and it is also very easy to install)


Also Memcached  Mysql optimization may help a lot.






--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: What makes _SERVER stop working

2009-08-03 Thread Ollisso
On Mon, 03 Aug 2009 20:26:35 +0300, Miller, Terion  
tmil...@springfi.gannett.com wrote:



All of a sudden this stopped working and keeps defaulting to A again

 if ($_SERVER['SCRIPT_FILENAME'] = browse.php ) {

$default = A;
}

else {
$default = ;
 }


it should be:
 if ($_SERVER['SCRIPT_FILENAME'] == browse.php ) {
...

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: What makes _SERVER stop working

2009-08-03 Thread Ollisso
On Mon, 03 Aug 2009 21:48:08 +0300, Miller, Terion  
tmil...@springfi.gannett.com wrote:






Thanks but it still doesn't work, it defaults to 'A' and I want it to  
default to show 'A only on browse.php all other pages should show NO  
default selections.

'


Create file with this content:
?php phpinfo()?

and run it with browser.

and then check - do you have what you need there ?



--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Problem: Writing into Files?

2009-08-02 Thread Ollisso
On Sun, 02 Aug 2009 07:11:27 +0300, Parham Doustdar parha...@gmail.com  
wrote:



Dear Ollisso,
I tried it with FLock() but it still didn't work. This is what I did:
[code]
$fp = fopen($f, r);
$count =fgets($fp, 1024);
fclose($fp);
$fw = fopen($f, w);
while (!flock($fw, LOCK_EX))
sleep(1);
$cnew = $count + 1;
$countnew = fputs($fw, $count + 1);
flock($fw, LOCK_UN);
fclose($fw);
[/code]

Am I doing anything wrong here?
Thanks!

Hello,

Actually you should do something like this (according to manual)

$f=fopen(file, r+);
while(!flock($f, LOCK_EX)) sleep(1);
$count  = fgets($f,1024);
ftruncate($f, 0);
fwrite($f, $count+1);
fclose($f);

Problem in your case: first time you open file for reading, but you don't  
flock it, so it can read non-writen file.





--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Problem: Writing into Files?

2009-08-01 Thread Ollisso
On Sat, 01 Aug 2009 08:20:23 +0300, Parham Doustdar parha...@gmail.com  
wrote:



Hi there,
I've written a counter for my blog, which keeps the count of visitors in  
a file. However, when the visitors get too many, it resets to zero. Why?


Here's the piece of code:

[code]
$f = $dir . '/view_counter' .EXT;
$fp = fopen($f, r);
$count =fgets($fp, 1024);
fclose($fp);
$fw = fopen($f, w);
$cnew = $count + 1;
$countnew = fputs($fw, $count + 1);
return $cnew;
[/code]

I'm thinking this is caused by two visitors visiting the page at the  
same time; but is there a way to fix it, perhaps the reading/writing  
parameter?


Thanks!



Check:
http://www.php.net/flock


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Clean break.

2009-08-01 Thread ollisso
On Sat, 01 Aug 2009 01:37:56 +0300, Paul Halliday  
paul.halli...@gmail.com wrote:


Actually, I don't think that regexp's are very slow :)

But I haven't tested them from that perspective.

You should just benchamrk different approaches :)
btw, not sure that substr will help you a lot:

first you have to get a begining of the time, block, then you have to find  
next X chars.


Btw, you can also do it with a quite simple regexp:
preg_match_all('#\[(.{20})#', ..
(where 20 is amount of characters you want to extract.)
or:
preg_match_all('#\[(.{8})(.{12})#', ..
(where 8 is first part of date, and 12 is second part of date.)

But then you will have to parse this string, to convert it to time, which  
could take time.


You should just benchmark different approaches, and check which is fastest.

PS: numbers 20,8, 12 are random, just put whtever you need :)
PPS: haven't tested regexps, just check the idea)





I was trying to stay away from regex as much as possible due to the
overhead? I might be wrong here.

This script will be parsing a lot of requests/sec. Thousands, maybe
more, which it also needs to toss into a DB. I want to try and keep it
as fast as possible. This is tricky when you don't know what you are
doing :). My coding is limited to hammering away at the search box on
php.net until I get a push in the right direction. It's just a hack
from there.

Using phpster's substr suggestion has already sped this up considerably.


2009/7/31 Ollisso olli...@fromru.com:
On Sat, 01 Aug 2009 00:22:21 +0300, Paul Halliday  
paul.halli...@gmail.com

wrote:


Whats the cleanest (I have a really ugly) way to break this:

[21/Jul/2009:00:00:47 -0300]

into:

date=21/jul/2009
time=00:00:47


...
Why not just use regexp ?

For example:

$string = long text.. multiply lines...
       [21/Jul/2009:00:00:47 -0300]

       [ 1/Jul/2009:00:00:47 -0300]

       [22/Jul/2009:00:00:47 -0300];


preg_match_all('#\[([ 0-9a-zA-Z/]+):([0-9:]+)
[^]]+\]#',$string,$matches,PREG_SET_ORDER);

print_r($matches);

Output:
Array
(
   [0] = Array
       (
           [0] = [21/Jul/2009:00:00:47 -0300]
           [1] = 21/Jul/2009
           [2] = 00:00:47
       )

   [1] = Array
       (
           [0] = [ 1/Jul/2009:00:00:47 -0300]
           [1] =  1/Jul/2009
           [2] = 00:00:47
       )

   [2] = Array
       (
           [0] = [22/Jul/2009:00:00:47 -0300]
           [1] = 22/Jul/2009
           [2] = 00:00:47
       )

)


--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php












--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Clean break.

2009-07-31 Thread Ollisso
On Sat, 01 Aug 2009 00:22:21 +0300, Paul Halliday  
paul.halli...@gmail.com wrote:



Whats the cleanest (I have a really ugly) way to break this:

[21/Jul/2009:00:00:47 -0300]

into:

date=21/jul/2009
time=00:00:47


...
Why not just use regexp ?

For example:

$string = long text.. multiply lines...
[21/Jul/2009:00:00:47 -0300]

[ 1/Jul/2009:00:00:47 -0300]

[22/Jul/2009:00:00:47 -0300];


preg_match_all('#\[([ 0-9a-zA-Z/]+):([0-9:]+)  
[^]]+\]#',$string,$matches,PREG_SET_ORDER);


print_r($matches);

Output:
Array
(
[0] = Array
(
[0] = [21/Jul/2009:00:00:47 -0300]
[1] = 21/Jul/2009
[2] = 00:00:47
)

[1] = Array
(
[0] = [ 1/Jul/2009:00:00:47 -0300]
[1] =  1/Jul/2009
[2] = 00:00:47
)

[2] = Array
(
[0] = [22/Jul/2009:00:00:47 -0300]
[1] = 22/Jul/2009
[2] = 00:00:47
)

)


--

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php