[PHP] Re: Which function returns a correct ISO8601 date?

2013-09-07 Thread Alessandro Pellizzari
On Sat, 07 Sep 2013 14:47:00 +0200, Simon Schick wrote:

 The method date(c) actually formats a date, fitting to the format
 defined in the constant DateTime::ATOM.
 
 Are both formats (with and without colon) valid for ISO8601, or is the
 documentation for the method date() wrong?

Yes:

http://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators

Bye.



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



[PHP] Re: how to see all sessions sets in server

2013-08-05 Thread Alessandro Pellizzari
Il Sun, 04 Aug 2013 20:47:37 +0430, Farzan Dalaee ha scritto:

Please use better quoting.

 So best way is use a script(javascript) to send ajax to server every 5
 second to check users is logged in or not? Is that okey?

It depends.

 I want to write chat module like facebook and i need a solution to find
 online users and way to send messages when users chat together, does any
 one write similar module like that?

Then knowing who is online is maybe the last of your problems.

You have to find a way to send the message to user B when user A 
writes something.

You absolutely need javascript. You just need to find out how to connect 
to the server. Have a look at socket.io, and find a php library that 
supports it. I think it is the easiets way.

Be aware that the load on your server will be huge, growing exponentially 
with the number of online users. You can't escape it, except by using 
different technologies (XMPP as a protocol, with a javascript client, or 
using node.js with socket.io, for example)

Bye.



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



[PHP] Re: how to see all sessions sets in server

2013-08-04 Thread Alessandro Pellizzari
Il Sun, 04 Aug 2013 13:32:55 +0430, Farzan Dalaee ha scritto:

 hi i want to write online user module for my site and i want to check
 $_SESSION['userID'] to find all users id who loged in but when i echo
 this code its return only current user detail how i can see all
 sessions?

You can't.

  or how i handle online users?

Every user has its session.

If you want to have a super user who has access to all the sessions, 
you can use the filesystem functions to read the directory in which the 
sessions get saved (it depends on the server configuration) or you can 
implement a session handler to save all the sessions in the database, and 
give access to that table to one user.

Bye.



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



[PHP] Re: AW: AW: PHP is Zero

2013-06-13 Thread Alessandro Pellizzari
Il Thu, 13 Jun 2013 13:27:51 +0200, BUSCHKE Daniel ha scritto:

 Why is PHP doing that?

Because a decision had to be made, and they chose to do it that way.

 I know it works as designed and I know it is
 documented like this but that does not mean that it is a good feature,
 does it?

It is a political decision. In a weakly typed language (by design) you 
have to decide how to convert types. it is documented:

http://www.php.net/manual/en/language.types.type-juggling.php

http://www.php.net/manual/en/
language.types.string.php#language.types.string.conversion

If you need stricter conversions, you can cast whatever you want to 
whatever else, and use ===

 So lets talk about the question: Is that behaviour awaited by
 PHP software developers?

Yes. At least for me.

 Is that really the way PHP should work here?

Yes. By design.

 May we should change that?!

No. It would break backwards compatibility. A lot. And it would make PHP 
a strongly typed language.

 BTW: I talked to some collegues and friends since my first post. They
 all guessed that 'PHP' == 0 is false within a few seconds. I think the
 weak-typed-PHP is a little to weak at this point.

Maybe because they are used to other languages.

Javascript has similar rules, but Python has different ones, as it is NOT 
weakly typed, just dinamically typed.

You just have to enter a different mindset. PHP is not Java or Python. It 
is PHP. You should use the way it was designed, not by any other 
languages rules.

One of the reasons I prefer PHP over Python is because it is weakly typed 
(another is the spaces-tab-madness)

Bye.



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



[PHP] Re: Compiler for the PHP code

2013-03-19 Thread Alessandro Pellizzari
Il Tue, 19 Mar 2013 08:46:22 +, Kevin Peterson ha scritto:

 My webcode written in PHP and it is running in the interpreted way. My
 problem is it is not giving the desired performance so want to try the
 compiler if any.

PHP gets compiled to bytecode on the server before being executed.
You can cache the precompiled code with (for example) APC.
Unless your code is several thousand lines of code (or your server very 
slow... 486-slow), the compilation phase is not that long.

I think your main problem can be one of:

1- wrong algorithm

2- long waits (database, files, network, etc.)

3- heavy calculations


Solutions:

1- find and use a different algorithm

2- Try to parallelize code (with gearman or similar, or via pctnl_fork)

3- rewrite the heavy functions in C, C++ or Go and compile them, then 
call them via PHP extensions or via gearman/fork.

Bye.



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



[PHP] Re: PHP 5.4 Help

2013-03-06 Thread Alessandro Pellizzari
Il Wed, 06 Mar 2013 08:41:43 -0800, Great Recordings, LLC ha scritto:

 Will someone tell me if the small module included on the bottom of this
 note will function properly under PHP 5.4? (Register_Globals turned
 off).  If it does not function properly with Register_Globals turned
 off, is there a way to make changes  to the module so it does function
 properly with Register-Globals turned off?

It is impossible to answer without knowing what is in prepend.inc (and in 
all the files included o required by it.
It is also impossible to know what is in the process identified by 
$processName (it is an external executable).

Per se, this small script doesn't need register_globals, but it calls 
external resources that could require it.

Your best bet is to find a relly good developer who can try to adapt the 
software to PHP 5.4.

IF the software is open source (or at least you have the sources).

I suppose he will not be able to do it in less than 20 days, so you 
should find a new hosting company that will allow you to keep 
register_globals on until the conversion (or the complete rewrite) is 
finished.

Bye.



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



[PHP] Re: shared memory on php servers?

2012-12-04 Thread Alessandro Pellizzari
Il Tue, 04 Dec 2012 11:49:22 +0100, rene7705 ha scritto:

 I'm wondering, what's the fastest way to put a large and deep array()
 structure in shared memory on a PHP server?

Using MongoDB. :)

Bye.



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



[PHP] Re: Variables with - in their name

2012-11-19 Thread Alessandro Pellizzari
Il Sun, 18 Nov 2012 01:09:11 -0500, Ron Piggott ha scritto:

 echo select name=\distributor- . $row['promo_code_prefix'] . - .
 $row['promo_code_suffix'] . \ style=\text-align: center;\\r\n;

 It could be wrote:
 
 ?php
 echo  $distributor-42-2;

You MUST disable register_globals in your php.ini

Once you have done that (and even before that...) you find your variable 
in $_POST['distributor-42-2']

(or $_GET, depends on your form method)

Bye.



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



[PHP] Re: Multithreading for OOP PHP

2012-10-31 Thread Alessandro Pellizzari
Il Wed, 31 Oct 2012 11:57:11 +0100, ma...@behnke.biz ha scritto:

 But it if PHP would be threadsafe, you would be able to run the Apache
 in a much faster and less memory using way.
 There once was a configure option in PHP to compile it threadsafe, but
 they dropped it for a reason.

Because PHP is threadsafe, but a lot of extensions are not.

Besides that, using fpm makes it fast enough.
On Linux a thread is not much faster that a new process, and uses nearly 
the same memory, but multiprocessing is much safer than multithreading, 
and much simpler to code.

So I don't think that thread safety is such a big deal.
 
Florian is more interested in the Java abstraction of threading than in 
the multithreading itself.

There are various ways to accomplish something similar, but it is not 
integrated in the language.

For example, you could use gearman to distribute database-intensive tasks 
on a server, or pcntl_fork to parallelize computation.

Bye.



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



[PHP] Re: Multithreading for OOP PHP

2012-10-31 Thread Alessandro Pellizzari
Il Wed, 31 Oct 2012 11:50:00 +0100, ma...@behnke.biz ha scritto:

 The drawback of forking is the memory overhead. With every fork you take
 the same amount of memory which is not the case if you could use real
 threads.

No, it is not.
Forking in Linux uses COW (copy-on-write), so a freshly-forked process 
occupies maybe 3-400 bytes of RAM. Only when writing on a memory 
location, that location gets allocated.

There are advantages (it is more safe, as you can't overwrite other 
processes' memory) and disadvantages (you can't simply read or write 
memory to communicate between threads, but must use IPC).

But speed and memory consumptions are not an issue.

Bye.



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



[PHP] Re: PHP as Application Server

2012-09-27 Thread Alessandro Pellizzari
Il Thu, 27 Sep 2012 12:28:00 +0200, Maciej Liżewski ha scritto:

 Sure there are
 disadvantages and other problems but what Alessando is saying is I
 would not use cure for cancer even if it existed because it can
 introduce other problems like overpopulation.

Uhm, no.

I see it as I would not use chemio if I could remove the cancer with 
laser therapy.

They are two ways to solve the same problem, and I think the non-
application-server way is the best.
It is similar to the Unix way: many small pieces tied together to reach a 
goal.
The application server is more like the Windows way: one big piece to 
reach a goal.

I understand sometimes the application server can be easier or fit 
better, but I think most of the times it is the wrong solution, 
expecially 
in PHP, but not exclusively.

Bye.



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



[PHP] Re: PHP as Application Server

2012-09-26 Thread Alessandro Pellizzari
Il Wed, 26 Sep 2012 17:23:35 +0200, Maciej Liżewski ha scritto:

 persistent application servers load resources only on startup (or when
 needed) and keep them in memory until programatically freed or until end
 of application (server shutdown). 

You don't mention the downsides:

- every application must be structured to not overwrite session data (you 
risk saving one user's data in another user's space)

- when changing even a single line in your code, you must restart 
(shutdown and start up) the whole app, closing all user connections and 
possibly losing all session data, forcing users to relogin.

- memory leaks are much more problematic

- you must manage threads, somehow, sometime.

Application servers have (IMHO) very little advantages (counters, and?) 
and a lot of disadvantages.

All (or nearly all) the advantages of application server have been 
superseded in PHP (precompiled caches, memcache, gearman, ... nodephp :) 
without losing its advantages (you can change a single file in the app 
and the precompiled cache auto-updates. You risk less with memory leaks, 
etc.)

Yes, some things are easier in Java (threading, syncronizing, etc.) but 
you can always write abstraction classes to do that for you.

I don't think I would use a PHP application server, even if it existed.

Bye.



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



[PHP] Re: Awkward time processing

2012-08-03 Thread Alessandro Pellizzari
Il Thu, 02 Aug 2012 09:25:40 -0700, Robert Williams ha scritto:

 $times = array(
 17 = '15:31',
 16 = '15:32',
 27 = '15:33',
 14 = '15:34',
 11 = '15:35',
 27 = '16:33',
 14 = '17:34',
 11 = '11:35',
 11 = '11:36',
 );

This will not work as expected. Try:

var_dump($times);

You lose 4 array elements.

Better:

$times = array(
 array('time'='15:31', 'c':17),
 array('time'='15:32', 'c':16),
 array('time'='15:33', 'c':27),
 array('time'='15:34', 'c':14),
 array('time'='15:35', 'c':11),
 array('time'='16:33', 'c':27),
 array('time'='17:34', 'c':14),
 array('time'='11:35', 'c':11),
 array('time'='11:36', 'c':11)
);

$result = array();

foreach ($times as $time) {
 if (!array_key_exists($time['time'], $result) {
  $result[$time['time']] = 0;
 }
 $result[$time['time']] += $time['c'];
}


Bye.



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