@beberlei although I am fully behind this, I am increasingly feeling that the hard coupling to libxml2 is the biggest problem with PHP+XML in general. It doesn't seem likely that it will ever support xsd 1.1 or generally anything new (which people do actually use in java/.net etc) and it does odd things with namespacing sometimes and it's not re-entrant so you can use zend allocators so it's not protected by memory_limit and <plethora of other niggles>...
I'm all for keeping userland up to date, but if you want to work on stuff with ext/dom then consider an abstraction layer, or at least keep it in mind when writing new code... full disclosure I have started playing a couple of times but never got anywhere, and I'm not in a position to work on it at the moment
there are licensing issues that mean that (afaik) libxml2 is the only option for something you can ship with PHP, but on windows you could use MSXML2 and potentially everywhere you could have the ability drop in sax or whatever via ext
it is a fucking insane amount of work though
@bwoebi power failure, sorry about that
oh right in fact, mildly entertaining story there, water works outside the building, they essentially cut through a 15KV master feed cable with bolt cutters thinking it was a water a pipe and took a whole block on one of the biggest roads in the city off for a whole day
still looking for a better place to run it btw... it needs 4 cores/4GB on a box with nginx and docker if anyone has one of those... resource usage is generally very low but big indexing operations (large new projects) can max it out for hours at a time. We could run it on a VPS easily but I'm not paying for it all by myself :-P
@Trowski Not totally sure without digging into it properly but iirc about 90% done, 0% tested. I do remember feeling very strongly that it was a shitload generally better than v2 and it's probably worth finishing
OK so please humour me for a second because I have clearly missed a lot :-P your "generics lib" is what, exactly? i.e. pre-processor, zend ext(?), other - specifically, does it involve run-time type checks?
the default method for posting forms is GET, my question is there any advantages for GET other than it is suitable small amount of data and it capable for web browsing cache and bookmarking
@ircmaxell OK right so I think I have a clear enough idea of what that is that I can sensibly ask... wtf are you doing that touches internals there? basically why are you talking about compiling stuff to native types? are you looking to build an extension or... surely you can't change the actual guts of an IS_ARRAY without changing stuff in php-src?
@ircmaxell OK so I presume you are doing an absolute crapload of static analysis there, it should be fairly easy to detect arrays that are populated in loops, many of which will have a predictable size so you can just pre-allocate it, job done. for everything else a constant growth of, say, 32? reasonable balance of reducing allocs and wasted mem, since they would be a lot smaller because they are native
I suspect the size of a lot of arrays (esp of the same type) can be pre-determined through static analysis/reading the value of some known counter var, I know I have written code like this a shitload of times:
for ($i = 0; $i < $analysable; $i++) {
$arr[] = expr($i);
}
// or
foreach ($analysable as $v) {
$arr[] = expr($v);
}
those are easy wins and (I would guess) account for enough cases to make a dumb fallback worthwhile
my gut says it's rare that that you have an array which is dynamically constructed and can't be analysed unless it involves external I/O, in which case allocs are the least of your perf problems
for ($i = $this->tableSize; $i < $newSize; $i++) { $this->indexes[$i] = self::INVALID_INDEX; $this->buckets[$i] = new HashTableBucket(new Variable(Variable::TYPE_UNDEFINED), 0, ''); }
In that case, is it reallocating? I mean I guess I could put a conditional on there, but then that means I need to compile a tracking variable to keep track of the size. Which means it is no longer an array, but a strict containing an array
Which, don't get me wrong, may not be a horrible idea...
Which also means, every array access requires a guard to determine if the size is correct or not
@ircmaxell I mean you could start with things that you can track the whole lifecycle of (i.e. vars that aren't leaked out of a given scope), dunno how much stuff would fall into that category but certainly some
and so that begs a question, do we generate code that could possibly be wrong but is silly fast (like C) or do we generate code that's 100% never going to fail (read past the end of an array for example) but is either 1) less efficient or 2) re-allocates a bit too aggressively
would love to hear @NikiC's thoughts here
There's another option in this case though. Since I will always be either masking an input hash, I am not sure the performance will really be impacted much, given it is always power-of-2.
So instead of compiling a guard to prevent outofbounds access, I can just rely upon the mask
wotdzero-sum of, relating to, or being a situation (such as a game or relationship) in which a gain for one side entails a corresponding loss for the other side
you are right about the libxml problems i suppose, my game plan was not to upend everything and start anew though, i need something small to work on :-) given dom has no primary maintainer i think its safe to make baby steps.
as for the namespace problems, that is actually PHPs dom implementation itself that is broken and does funky stuff. libxml would handle it if it were implemented correctly.
@ircmaxell typically you round up to a fraction of the next power of two (I propose a quarter of the next power of two), with a minimum allocation chunk size, e.g. 64. Then you take rounding_size = max(64, ((size - 1) >> 2) & ~(((size - 1) >> 2) - 1)); rounded_size = (size + rounding_size - 1) & ~(rounding_size - 1); that way you have a maximum overhead of 12,5%. Still some overhead, but you obviously cannot avoid having any overhead at all (heck, our emalloc() with bins has the same issue)
(If my bitshifting logic is correct, did it off my head now)
you obviously have to store the size of the allocations. (and that's the point where you use your own MM.)
but afaik malloc does also leave some space (it's not like each reallocation call would be expensive, only these which actually move memory)
in the end, at whatever level you implement it, you will have to execute that very logic, whether it's in the native allocator, in your own allocator or directly accompanying the array.
@beberlei there's an issue I ran into related to exporting nodes whereby it didn't copy the ns decls, either not at all or incorrectly, and that I think is fixable internally, I'll try and find the specific issue
@DaveRandom your comment on libxml2 peaked my interest though, its fascinating that there is no xml library in c that is more modern when libxml2 really not implements a lot of the more recent changes (xsl and xpath related for example).
@PeeHaa Thanks. Unfortunately I'm not good in english :( But I'm work on it :) Also 2: I'm do not know if 7.5-7.6-... is in roadmap. So if yes, then 7.5 - warning, 7.6 - error etc. If not, then 8.0 - warning etc.
@bwoebi with that approach, wouldn't I need to branch on every access to ensure I am not overflowing? With a power-of-2, I could just bitmask it avoiding a branch all together
For the allocator itself, I am just calling out to malloc for now.
@PeeHaa Potentially it may provide heavily impact to large legacy projects. Slow growth will give more time to prepare migration. But maybe I'm too cautious.
Hello Dear, I Have a Shared Server, I am Using a Core PHP Code For My Website on Local Is Working Properly but If I'm going to online working properly but if i'm login my admin panel then show connection error - Connection Error SQLSTATE[42000] [1203] User database_user already has more than 'max_user_connections' active connections
@beberlei I mean there are a few (oracle, saxon etc), but afaik libxml2 is the only real foss option, certainly the only one that is compatible with the PHP license. Windows is easy (MSXML2 is extremely full featured and well tested) but other places not so much. I suspect, however, that a lot of *nix envs will either already have, or easily have the ability to install, stuff that java depends on which could be wrapped up into a pecl ext
@LeviMorrison regarding not binding $this if it's not necessary: I think this won't work because things like Foo::bar() may use $this, if it's compatible
the fact that it doesn't use zend allocators has always made me uncomfortable though, seems like a big fat DoS vector as memory_limit isn't respected, so if you can trick an app into loading a 2GB XML doc then you are gonna have a bad time
@DaveRandom yeah, i checked the libxml docs and code, it doesn't even provide a simple way to overwrite the memory allocator for clients of the library. I always feel thats weird of core libraries not to provide
yes I must admit that my grasp of the actual problem is sketchy at best. The practical upshot is that if you try the dumb approach then it segfaults a lot
@JoeWatkins my system install is still on 7.0. The other versions didn't have openssl configured, so I simply didn't bother. I'm fixing that now by recompiling everything
Though that gives me a problem in the static analyzer, in that how do I know the types involved. I can make a generic in the docblock, but man that gets complex quickly
@LeviMorrison As this also works with call_user_func('Foo::bar') and $fn('Foo::bar'), I think automatically determining $this binding may not be a good idea. It's not as straightforward as it seems.
Additionally this would make the liveliness of the objects much more unpredictable / sensitive to the code - currently it's "obvious", the object will be destroyed once all non-static created Closures stop referencing it (and nothing else as well)
@Allenph I have two resumes right now, one I need to polish up, which I'll be doing today or tomorrow for sure. Trying to knock out my dad's job today so that I can get that off my plate...and give me some more programming experience...
using PDO how can i prepare $_POST? I am using $stmt = $Conn->prepare("INSERT INTO, does that work, or do i need to clear the $_POST before putting the value in my SQL statement?
@Geoffrey it depends on how you're doing the binding. If you're looking for general advice, I'd say just try it and see what happens, using what you've read as a rough example. If you're encountering an error/issue, I won't be able to help without sample code (gist or pastebin), redacting the sensitive bits.
@Tiffany Thanks. Basically, we’re taking an DDD approach to an application we’re building at work. A colleague’s suggested using commands to fetch data from services, but my (limited) understanding is commands would be used to send “messages” (i.e. to persist/update data). Am I right in thinking this? And if so, what approach would one use to fetch data? Repositories, query objects, other?
@MartinBean commands would be used to decide what to do next, if the current code isn't capable of handling it......e.g. on site I look after we can have a form be submitted, and then depending on some settings, that data might trigger an email to be sent, or some data to be pushed to salesforce.
The form processor for us would just accept the form data, lookup what should happen next from the settings in the database, and issue a 'send email command' and a 'push to salesforce command'.
But inside each of those command handlers, and the initial form processor, we just read dat from services as normal
@Danack Someone else is using commands to essentially fetch data from a database, though. Which to me doesn’t feel like an appropriate use of a command?
@NikiC Were you talking about binding $this on short closures? Changing the auto binding vs. long closures would probably be a mistake. Could support static fn() => …
I don't think changing $this binding is a problem (the only thing it effectively impacts is GC behavior) -- as long as we can somewhat reliably detect whether or not $this is used, which we can't
i would like to subtract a date. The date is pulled out of a database and is a string, what is the best way to work with this? I've tried DateTime but it keeps throwing errors about the date being a string.
@beberlei i'm just echoing to see if it works and comes out correctly. i am trying to compare a date less 2 weeks against current date. if it's true then it runs some magic
People bring that up, but I think it would be rare that you would use them in ways that might potentially be visually misidentified, and even then I don't think they'll be ambiguous, particularly if your editor highlights keywords.
We reuse symbols all the time. & deals with references, bitwise-and, and so on.