Yeah: documenting that the method returns false on failure would appears to stop implementers from throwing exceptions on failure. They have to return false in order to meet the interface's contract, so they cannot throw an exception. This seems really odd to me, which is why I wondered if I was missing something.
I suspect that implementers will end up ignoring the return value of these methods entirely and doing the sensible thing of throwing exceptions on error, but then it seems silly that the interface has documented behaviour which everyone will break. This also means that users will have to handle both exceptions and a false return value.
TTL is in seconds, and a negative or zero TTL automatically expires
Aha, I missed that bit of the docs, thanks. I think the doc comments could probably do with some work, since that's what people are going to read from their editor.
There are a number of methods which return a boolean indicating whether or not an error occurred. However there's no way to get what the error was. This makes the interface feel very C-like, and not at all like a modern object-orientated language.
Why do these methods return a bool, rather than throwing an exception on failure?
In addition, get, getMultiple and has don't return a bool, so there's no way of indicating an error in the same way as the other methods.
As a separate issue, the $ttl parameter to set can take an int, but there's no indication of the units of this value in the doc comment. What happens if a negative or zero interval is given? Is an exception thrown? What?
I did read something (no source, for now, so don't take me at my word) which said that a notebook isn't such a bad idea. The sort of person who's going to break into your house and steal your computer isn't the sort of person who's going to steal your password and try and get your identity / bank account. They're two different demographics.
The person stealing your computer is shitting his pants trying to get in and out as quickly as possible, and already has a fair few hundred quid's worth of tech in his hands. He's not going to rifle through your notebooks in the offchance that there's a password he can use in there.
Notebooks, on the other hand, are very hard for malware to steal...
That said, I use and love KeePass and Keepass2Android.
I see it as a bit of an ugly workaround. Sure it's useful and I'm glad to see it, but it shouldn't be necessary. I don't want to start a PHP vs <some language> war, but other languages have solved this problem through nicer syntax, essentially:
// Ruby
some_array.map{ |element| element['name'] }
// Python
[element['name'] for element in some_array]
// PHP's array_map
array_map(function($element){ return $element['name']; }, $some_array);
// PHP's proposed list comprehensions
[foreach ($some_array as $element) yield $element['name']];
// PHP's array_column
array_column($some_array, 'name');
If PHP had nicer lambda or list comprehension syntax, array_column wouldn't be necessary.
In an ideal world, I'd like to see proper OO support (har har), and shorter lambdas, so something like the following would be possible:
I think I'm correct in remembering that if you haven't modified the config file which was installed by pacman, then a new version of the config file will simply overwrite the old one. .pacnew files only appear when you've made changes to the old config file, and pacman doesn't want to throw away your changes.
So let's assume you have 2 virtual sites using your server, and that 5% of people viewing those 2 sites are actually hitting the server at any one time. Let's also ignore the long-polling stuff for now.
With a thread pool of 150, then we can handle 3000 or so users using those sites at once
If 5% of 3000 people are hitting your server at once, that's 5% of 3000 = 150 simultaneous connections.
This is how many working threads you have, meaning that your server's running at capacity.
If, however, just one of those virtual sites is running your CMS with its single long-polling worker, and a mere 100 users are using your CMS, then the number of users you can support between both sites drops to 1000.
Each user of your CMS ties up one worker thread permanently due to the long-polling (assuming each user only has one long polling connection). This means that there are only 50 free worker threads to handle normal requests, that is, 50 simultaneous connections are supported. 50 / 5% = 1000 users.
If 150 users are using your CMS, then both websites grind to a halt.
All the worker threads are tied up doing long-polling, meaning there are none free to serve other resources. Like web pages.
Also be aware that each worker takes somewhere around 5-15megs,
ps -ylC httpd --sort:rss
and two many active workers could cause to start swapping, which will bring everything to a halt.
Depends on how big your max thread pool is. My defaults for apache are set at 150 workers max.
Remember than each thread that's handling a long poll can't handle any incoming requests.
So let's assume you have 2 virtual sites using your server, and that 5% of people viewing those 2 sites are actually hitting the server at any one time.
Let's also ignore the long-polling stuff for now.
With a thread pool of 150, then we can handle 3000 or so users using those sites at once.
If, however, just one of those virtual sites is running your CMS with its single long-polling worker, and a mere 100 users are using your CMS, then the number of users you can support between both sites drops to 1000.
If 150 users are using your CMS, then both websites grind to a halt
Also be aware that each worker takes somewhere around 5-15megs, and two many active workers could cause to start swapping, which will bring everything to a halt.
EDIT: Assuming you combine the two long-polling scripts.
The recommended approach seems to be to run a separate, dedicated server that's intended to just handle long-poll requests. Google for "comet server".
This does, of course, make it a lot harder to just provide people with a zip package of your cms, which they can deploy by unzipping. If you need to keep with pure PHP, you'll have to weigh up long polling vs short polling.
However, it looks a lot like pure PHP files are being used to handle the server side of the long poll, which is bad. The reason being you now have two worker threads permanently tied up for each user (chat_poll and aspect_poll), and your thread pool is going to disappear pretty rapidly.
Edit: Also, what's with all the print "<script>window.location=\"../index.php?id=$newID\"</script>";? What's wrong with a good old HTTP redirect?
I use it for salt generation, so not so much of an issue.
Agreed for password generation though. Although I'd probably look for a php port of linux's passwd command
Your implementation will have roughly the same proportion of numbers, lowercase and uppercase, which, as there are fewer numbers than letters, means (I believe) that your entropy is lower than it would be otherwise.
According to that wiki page, the service is
systemd-udevdInstalling directly on arch is very much not supported, officially. Use the docker image instead: completely painless, supported, and no breakages.
If you read it again, you'll see that I asked questions. I imagine other people reading this PSR for the first time will have similar questions.
People like yourself can provide answers to these questions, if you're more in the know than I am.
Yeah: documenting that the method returns false on failure would appears to stop implementers from throwing exceptions on failure. They have to return false in order to meet the interface's contract, so they cannot throw an exception. This seems really odd to me, which is why I wondered if I was missing something.
I suspect that implementers will end up ignoring the return value of these methods entirely and doing the sensible thing of throwing exceptions on error, but then it seems silly that the interface has documented behaviour which everyone will break. This also means that users will have to handle both exceptions and a false return value.
Aha, I missed that bit of the docs, thanks. I think the doc comments could probably do with some work, since that's what people are going to read from their editor.
There are a number of methods which return a boolean indicating whether or not an error occurred. However there's no way to get what the error was. This makes the interface feel very C-like, and not at all like a modern object-orientated language.
Why do these methods return a bool, rather than throwing an exception on failure?
In addition,
get,getMultipleandhasdon't return a bool, so there's no way of indicating an error in the same way as the other methods.As a separate issue, the
$ttlparameter tosetcan take anint, but there's no indication of the units of this value in the doc comment. What happens if a negative or zero interval is given? Is an exception thrown? What?I did read something (no source, for now, so don't take me at my word) which said that a notebook isn't such a bad idea. The sort of person who's going to break into your house and steal your computer isn't the sort of person who's going to steal your password and try and get your identity / bank account. They're two different demographics.
The person stealing your computer is shitting his pants trying to get in and out as quickly as possible, and already has a fair few hundred quid's worth of tech in his hands. He's not going to rifle through your notebooks in the offchance that there's a password he can use in there.
Notebooks, on the other hand, are very hard for malware to steal...
That said, I use and love KeePass and Keepass2Android.
I see it as a bit of an ugly workaround. Sure it's useful and I'm glad to see it, but it shouldn't be necessary. I don't want to start a PHP vs <some language> war, but other languages have solved this problem through nicer syntax, essentially:
If PHP had nicer lambda or list comprehension syntax, array_column wouldn't be necessary.
In an ideal world, I'd like to see proper OO support (har har), and shorter lambdas, so something like the following would be possible:
It's a pity PHP doesn't have a decent map function (it's got
array_map, but it's an ugly blighter). That would makearray_columnunnecessary.Interesting. I'll take a look when I get some time. I can't honestly say I tested it much
I should have said it's written for PHP5.4
That doesn't match up with your expected result. Using anything as the separator (as you stated) surely gives a result of
Anyway, I wrote a function which implements the spec as you describe it, as someone's already implemented the spec as given by your example:
I think I'm correct in remembering that if you haven't modified the config file which was installed by pacman, then a new version of the config file will simply overwrite the old one. .pacnew files only appear when you've made changes to the old config file, and pacman doesn't want to throw away your changes.
Look at how FuelPHP does it
Logic and presentation should be separate. You're mixing presentation (HTML) with logic (PHP code that's doing process-y things).
If 5% of 3000 people are hitting your server at once, that's 5% of 3000 = 150 simultaneous connections.
This is how many working threads you have, meaning that your server's running at capacity.
Each user of your CMS ties up one worker thread permanently due to the long-polling (assuming each user only has one long polling connection). This means that there are only 50 free worker threads to handle normal requests, that is, 50 simultaneous connections are supported. 50 / 5% = 1000 users.
All the worker threads are tied up doing long-polling, meaning there are none free to serve other resources. Like web pages.
ps -ylC httpd --sort:rssCommon sense
Depends on how big your max thread pool is. My defaults for apache are set at 150 workers max.
Remember than each thread that's handling a long poll can't handle any incoming requests.
So let's assume you have 2 virtual sites using your server, and that 5% of people viewing those 2 sites are actually hitting the server at any one time. Let's also ignore the long-polling stuff for now.
With a thread pool of 150, then we can handle 3000 or so users using those sites at once.
If, however, just one of those virtual sites is running your CMS with its single long-polling worker, and a mere 100 users are using your CMS, then the number of users you can support between both sites drops to 1000.
If 150 users are using your CMS, then both websites grind to a halt
Also be aware that each worker takes somewhere around 5-15megs, and two many active workers could cause to start swapping, which will bring everything to a halt.
EDIT: Assuming you combine the two long-polling scripts.
The recommended approach seems to be to run a separate, dedicated server that's intended to just handle long-poll requests. Google for "comet server".
This does, of course, make it a lot harder to just provide people with a zip package of your cms, which they can deploy by unzipping. If you need to keep with pure PHP, you'll have to weigh up long polling vs short polling.
I think 0bp's point was that you don't have separate views, instead choosing to mix HTML into various functional PHP files.
MVC is popular for a reason, and it's worth looking into why.
You're using long polling, which is good.
However, it looks a lot like pure PHP files are being used to handle the server side of the long poll, which is bad. The reason being you now have two worker threads permanently tied up for each user (chat_poll and aspect_poll), and your thread pool is going to disappear pretty rapidly.
Edit: Also, what's with all the
print "<script>window.location=\"../index.php?id=$newID\"</script>";? What's wrong with a good old HTTP redirect?My server uses duplicity, using a version of the wrapper dt-s3-backup, to back up to amazon s3.
Nightly incrementals with a full backup every two weeks. It's saved my bacon more than once.
Yeah, but cookie stealing is entirely possible
Doxygen for me. Cross-compatible with C (which I also work in), and pretty much compatible with phpDocumentor.
Don't forget the good ol' array_merge (stolen from jQuery's way of doing things):
That way you get the option of leaving out parameters if you want, and you don't have to check that all required params have been specifies.
I use it for salt generation, so not so much of an issue. Agreed for password generation though. Although I'd probably look for a php port of linux's passwd command
I tend to go with:
Your implementation will have roughly the same proportion of numbers, lowercase and uppercase, which, as there are fewer numbers than letters, means (I believe) that your entropy is lower than it would be otherwise.