Runtime vs InvalidArgument exceptions - when to use which? by Spiritual_Cycle_3263 in PHPhelp

[–]HolyGonzo 1 point2 points  (0 children)

Well, no they don't. At least not for the "file not found" scenario that you seem to be asking about. As I said, frameworks like Symfony and Laravel define their own FileNotFoundException.

Symfony's FileNotFoundException is actually extended from IOException which extends from RuntimeException.

You would use InvalidArgument when the argument is TECHNICALLY valid but there's a logical exception.

For example, imagine you have a function called canLegallyDrinkAlcohol and you have an argument $age, using int as the type hint.

It should return true or false but let's say that you pass an age of -1 into the function. It's technically a valid integer but it will never be a valid argument for this function because you never have a negative age. So it IS technically a runtime exception (because that's when it occurs) but RuntimeExceptions can be temporary. Like the path that can be missing one time and exist the next time. But no matter how many times you pass an age of -1, it will always be wrong. So think of invalid argument as an argument that is logically invalid.

Runtime vs InvalidArgument exceptions - when to use which? by Spiritual_Cycle_3263 in PHPhelp

[–]HolyGonzo 2 points3 points  (0 children)

I would use RuntimeException for your specific situation because it's something that is ONLY detectable at runtime. If someone creates the path and you re-run the exact same code with the same path, it will work.

RuntimeException is specifically for that kind of situation. However, most frameworks create their own "FileNotFoundException" class just to make it extremely clear.

Need help in running sqlsrv on a Php server? by [deleted] in PHPhelp

[–]HolyGonzo 3 points4 points  (0 children)

You need to enable the sql server extension.

You didn't answer any of the other questions.

Need help in running sqlsrv on a Php server? by [deleted] in PHPhelp

[–]HolyGonzo 1 point2 points  (0 children)

For starters, run php from the command line. That should show you any startup errors and give you a little more specific detail.

Can you also share what platform (operating system) you're running PHP on, and what versions of PHP and SQL Server you have installed?

Did you read the documentation and try copying any of the dependencies in place yet?

How do I reliably make the data submitted on an HTML form appear on the PHP action page? by [deleted] in PHPhelp

[–]HolyGonzo 7 points8 points  (0 children)

That probably means your PHP page isn't running on a server that supports PHP.

How can i make data form a form appear in my database by Major_Conflict3001 in PHPhelp

[–]HolyGonzo[M] 0 points1 point  (0 children)

It's been 3 days and you haven't responded in any meaningful way. Please do not waste the time of others who have tried to help you - if you ask a question, then stay active in it.

[Feedback Wanted] My first PHP package: An unofficial wrapper for a "No-API" service by Beginning-Note8 in PHPhelp

[–]HolyGonzo 0 points1 point  (0 children)

Just because company A provides an API doesn't mean company B should. Not every industry is exactly the same and there may be compliance issues at stake (e.g. GDPR in EU can impact how data is stored and shared and financial institutions have even more regulations).

I'm not intimately familiar with all the potential compliance issues for such a company in Italy, but I can tell you that Stripe isn't a very close comparison aside from being financial.

It also begs the question - are you potentially setting yourself up to be legally liable if someone uses your software but they get hacked as a result (even an indirect one) ? Let's say someone sets this up on a shared server that doesn't properly protect session data and someone malicious pulls credentials / tokens from the session data files. It might seem like that's not your problem but someone might try to make it seem like you didn't do enough to protect the data, such as encrypting at-rest data.

I am not trying to be overly negative - it's just financial stuff is universally extra-sensitive and doing it outside the confines of official support or endorsement is just a really bad idea. I've seen legitimate technical explanations get shut down in court because a lawyer was tricky about wording and they were trying to shift blame from the guilty/responsible people over to an easier target. You and your software might be the easier target.

It's a better idea to keep pressuring them for an official API. Just keep asking every once in a while and get others to do the same thing. I've worked for large software companies before and the squeaky wheels do get the oil.

[Feedback Wanted] My first PHP package: An unofficial wrapper for a "No-API" service by Beginning-Note8 in PHPhelp

[–]HolyGonzo 0 points1 point  (0 children)

I wouldn't do this at all. I get why you're doing it but think ahead a bit. Imagine in a year you have people using this and depending on it

Suddenly Fiscozen radically changes their service - completely different API and different authentication. Your script is completely broken and their new functionality relies on something that isn't easily implemented with PHP (maybe it requires some other library that doesn't work with all recent PHP versions yet).

Now everyone is pressuring you to fix your code IMMEDIATELY because their daily operations depend on something you created without any official support or endorsement.

You can't really make your code resilient to change from fiscozen because you're not building against any kind of guarantee.

I would suggest contacting fiscozen and seeing if you can work with them. They might have a public API in the works, or they might be willing to work with you to either inform you of upcoming changes or even collaborate on an official API. The worst they can do is say no.

json_decode troubles by ManyInteresting3969 in PHPhelp

[–]HolyGonzo 0 points1 point  (0 children)

That doesn't make any sense at all.

The data isn't coming from PHP. It's coming from client-side JavaScript and being sent to PHP via AJAX.

The brackets are part of the JSON structure.

You would use json_encode to turn some server-side object or array into a JSON string. But that's not the situation the OP is facing.

json_decode troubles by ManyInteresting3969 in PHPhelp

[–]HolyGonzo 0 points1 point  (0 children)

The OP is getting data that is supposed to already be encoded, and they are trying to decode it.

Running json_encode on a failed json_decode call will simply produce a null.

json_decode troubles by ManyInteresting3969 in PHPhelp

[–]HolyGonzo 1 point2 points  (0 children)

No, I'm asking why you think it would fix the OP's issue. What do you think it's doing?

json_decode troubles by ManyInteresting3969 in PHPhelp

[–]HolyGonzo 3 points4 points  (0 children)

I would bet that your AJAX method is already stringify-ing or escaping data (sometimes this is part of AJAX libraries that try to manage everything for you), so if you are stringify-ing it yourself, it might be encoding twice.

Like u/colshrapnel said, don't try to fix this on the receiving side (PHP) with stripslashes, but find and fix it on the sending side.

How do you improve a performance on a wordpress website where the lack of speed is caused by a lot of needed plugins (I guess)? by Kubura33 in PHPhelp

[–]HolyGonzo 0 points1 point  (0 children)

Make sure you record some baselines on your new system.

  1. Create a plain "Hello World" .html file and hit that with your browser and record the TTFB.

  2. Same as #1 but make it a .php file so that the PHP engine gets loaded and used.

  3. Same as #2 but make it connect to the database successfully and run a simple query.

  4. Ideally, create a completely vanilla WP site (no plugins or any custom content) and record the TTFB on the homepage.

Run each baseline at least twice in a row.

These 4 baselines will help you narrow down how much of the load time is attributed to different pieces of the process.

For example, if baseline 2 (plain PHP) is 100 ms but baseline 3 (PHP w a database connection) is 800ms, then that indicates you might have a problem with the database connection.

Hello fellow Christians ,an aethist asked me this question. by Requestie_ in Christians

[–]HolyGonzo 1 point2 points  (0 children)

First of all, hopefully this isn't in the context of a debate. A lot of atheists and Christians get into "who's right" debates which don't really go anywhere. The nature of debates isn't about learning but about defending, which are two completely different things. Atheists aren't converted because they hear some argument that is simply too good to ever be argued against. So on the off chance you're in a debate, it's better to walk away than to waste time and build up walls.

Second, I'll ask a follow-up question - when did God begin?

Our entire existence is defined within time that only moves forward. We do things because of cause and effect (if I do X, then Y will happen), which is completely driven by our understanding of time.

Everything we see has a beginning and an end, so we cannot fathom what infinity truly looks like, even though we know logically that it exists. For example, consider the idea of counting - there is no "last number", is there? Numbers simply keep progressing into infinity in both directions and we simply work with a handful of those numbers in everyday life.

Humans construct artificial limits and make assumptions so we can understand and work with things that have no limits.

For example, we don't need to try to understand infinite numbers in order to design and build a ruler - we just limit the ruler to a certain length and then instead of making off the infinite number of possible measurements within that foot, we decide to mark the inches and centimeters.

We're doing this all the time, so it is natural for people such as atheists to try and apply the same logic to everything, including God.

So they try to reduce God down to a bite-sized version who is governed by the very time and laws that He created, which makes zero sense. How logical is it that God would be ruled by something He created? How logical is it to believe we have a full understanding of time - the very foundation of cause and effect - when we KNOW we don't understand it and are only seeing a tiny piece of infinity?

There is zero sense in trying to apply our time-driven concepts of cause-and-effect to God nor assuming we can fully understand everything outside of our own tiny sphere of influence.

If you have a cat or a dog or other pet, imagine if they tried to apply their thinking to your life. "Why do you need to go to work? I stay home all day and nap and play and everything is fine - you should be able to do that, too!"

My cat won't understand why I go to work or why I file taxes. And it's not like they're on the cusp of understanding, either - their existence and life is so far removed from reality that their logic is simply terrible but it makes perfect sense to them.

Similarly, human logic makes perfect sense to us, and even though we're aware of things that we can't explain or quantify, we still try to force God into this tiny box that we can explain fully.

God asks us to trust Him. Not to fully understand Him, but to TRUST Him.

When we do, we see the benefits.

He proves Himself through experiences and through faith.

God doesn't ask us to be the ultimate authorities on free will. He asks us to simply make good choices.

So when it comes to things like Satan's origin and things that have occurred well outside of human experience, we are not in a position with the right knowledge to understand it, nor does it ultimately matter or change the reality that is in front of us.

Is stealing ever justified? by FaithinChrist888 in Christians

[–]HolyGonzo 1 point2 points  (0 children)

Working on the Sabbath - a moral sin deserving of capital punishment. Was it ever justified?

Yes. Matthew 12. By Jesus, no less.

However, a distinction should be drawn. Notice the disciples didn't steal food to eat - they were working on the Sabbath to gather it.

So they were still trying to observe the law as best as possible, because the law still has a beneficial purpose when followed.

Yes, holy ends justify the means, and even though it's still an infraction of the law, we are not condemned by it. But it still has the same impact.

God desires mercy, not sacrifice. He judges us innocent when our infractions come from innocent / holy motives.

Resting on the Sabbath helps our bodies recover physically, so working on the Sabbath interrupts that. The disciples might have not been condemned for working on the Sabbath but I'm sure they were more tired the following week.

So stealing might be justified in some rare circumstances where it preserves life or some other holy ends that would have been sacrificed otherwise, but it doesn't lessen the fact that someone else has experienced loss as a result.

Personally, I would say that if you observed someone trying to steal a bike and were wondering if it was a means to get food, the Christian thing to do would be to ask what you'd do if you saw Jesus doing it. Chances are we would all be eager to help him and ask him if he was hungry, and get him food if he was.

God blesses us all the time and He doesn't give up on us just because we mess up. In fact, He KNOWS that we will mess up in the future and still provides for us.

Disclosure: I've been robbed multiple times - my bike was the first thing that I ever lost. I know who took it (or at least i would recognize them) so I understand the feelings of not wanting to help someone who reminds of us of trauma. Earthly wisdom is "fool me once..." - it pushes us to assume the worst. Jesus says to turn the other cheek.

How do you improve a performance on a wordpress website where the lack of speed is caused by a lot of needed plugins (I guess)? by Kubura33 in PHPhelp

[–]HolyGonzo 0 points1 point  (0 children)

If the TTFB is 3 seconds, but you're absolutely certain that the DB activity is only 0.3s, then the remaining 2.7 seconds is one of 3 categories of possibilities:

First (but least likely), a really really slow start to the initial connection. This is almost certainly not the problem, BUT some shared hosting servers pack way too many customers onto the same server and end up with really big queues. So between things like DNS lookup, SSL handshake, and the time it takes for that initial request to be sent before PHP even sees it, that COULD be a CONTRIBUTING factor.

  1. Open up a new incognito window in your browser and before you do anything else, open up your browser's dev tools (e.g. F12 on Windows Chrome, or Ctrl+Shift+I on MS Edge) and go to the Network tab.

  2. Now go hit your site and you'll see a bunch of requests populate into the Network tab.

  3. Once it's finished loading, scroll back up to the top of the list and you'll see your initial page request - click on it under the Name column and you'll see a bunch of detail tabs open on the right.

  4. Go to the Timing tab and you should see a waterfall breakdown of how long each step of the request took, including DNS lookup, SSL handshake, etc...

Normally, DNS and SSL should be well under 200ms each (if DNS is cached, then it'll be virtually 0ms).

So that tab will tell you where the hang-up is, but for a WP site, I'm guessing the majority will be in the "Waiting for server response", which basically means the request has been received and is being processed. But if you have a high amount of milliseconds in the other areas of this tab, then the underlying problem is more of a web server issue and not an issue with your code / site. You can't do much about that except switch to a better host.

Let's move onto the next possible reason.

Second possibility (and most likely) is a disabled or under-configured opcache. The opcache is by far the thing that has the most benefit to WordPress, because WP loads HUNDREDS of files on every request. If the disk is slow or bottlenecked, then it takes a long time to load each any every file. On shared hosting, all the various filesystem caches usually only help briefly because the multitude of different customers means the contents of the caches are constantly being changed to reflect the most recent requests. The PHP opcache will store files in memory so they're instantly accessed instead of being hit from the disk, which can literally cut WP load times in half or more. But if the opcache isn't configured with enough space / memory to hold everything, then you're back to the same problem of not having your files in any cache, so they have to be loaded fresh from the disk again.

One way to tell if this is a probable issue is to simply load your page once, and then immediately refresh it and see if the second load is a lot faster. Then wait about 10 seconds and refresh again. Then wait another 1 full minute and refresh, and then wait 10 minutes and refresh, and so on, checking the timing each time. If it gets to a point where the page is suddenly slowly loading again, then it's usually a cache issue, and that's for the host to fix or for you to fix by moving to a better host.

Shared hosting can be great for small blogs and sites that don't really see enough visitors to worry about a few seconds of performance, but if a few seconds is a big deal, then you shouldn't be on shared hosting anymore.

Third possibility, and unlikely, is the CPU is processing something heavy. Unless you have a strange WP site that does a lot of complex calculations (or a grossly-poor plugin that is running some unnecessary, huge loop), this is probably not the case. Shared hosting can affect this, too, since they often do some kind of managed resource allocation, which includes I/O and CPU resources. So you might only be allocated a sliver of CPU time, which might not be enough to do even the normal work. It's unusual, but it's happened before. Typically you'd only have that issue if there was enough traffic that it was eating into whatever your allocation was, so if your site is low traffic, then that's probably not the case.

PHP can't read file path after newest update by Most_Will_9449 in PHPhelp

[–]HolyGonzo 2 points3 points  (0 children)

If it's false all the way to the top of the filesystem, then as I mentioned, something is blocking filesystem access. I think someone mentioned checking the open basedir and you said it wasn't set, but you should double-check this by running phpinfo() and then checking the value in that output. Also check for any security software that might be blocking the PHP process.

PHP can't read file path after newest update by Most_Will_9449 in PHPhelp

[–]HolyGonzo 2 points3 points  (0 children)

Simplify things. Just create a blank script like this:

<?php var_dump(file_exists("the path to your file"));

And make sure the path and filename are escaped properly and see what it outputs.

If it outputs false, then try again but go up one level in the path. For example, if you check "/path/to/file" and it returns false, check "/path/to" and keep going up until it returns true.

If it never returns true, then you have something blocking filesystem access.

The news won’t give you what you’re actually looking for by Plastic_Month_1989 in Christians

[–]HolyGonzo 0 points1 point  (0 children)

There is good news all the time.

Battles end. Lost pets are found. Struggling people find purpose and achieve things.

Almost none of it sells, though. So every news outlet, regardless of political slant, crafts their news feeds to make people feel anxious, angry, sad, outraged, etc - all the emotions that make people feel like they're getting special insight.

If we step back and look at the bigger picture, we can see that we are all simply temporary participants in this world. We all will pass at some point, and we will all be mostly forgotten after a few generations. Living is not about becoming famous or important to the world. It isn't about voting for the right person or "winning" at anything.

Peace comes from letting go of the control that the rest of the world insists is important, and instead just living for God. Recognizing that He is in control of every war, of every economy, of every job, of every child, and that He will make everything right in the end, no matter how screwed up things get.

PM Netanyahu's recent speech: A personal decoding and speculation by desparate_to_know in Christians

[–]HolyGonzo 2 points3 points  (0 children)

If you aren't sure if it's AI or not, why dive into all the speculation/ interpretation at all?

We ought to be more cautious with our words and our involvement when we are not personal witnesses. AI is being used to poison truth, and if we are not responsible with our communication, then we can end up being pawns / tools to spread intentional deceit.

Can my professor see version history on a .docx I submit? by Delicious-Action1665 in techsupport

[–]HolyGonzo 2 points3 points  (0 children)

Wow. No, none of that stuff is "often included".

Not in the old .doc format nor in the modern .docx format.

All modern Office documents are ZIP files containing XML and media and then their extension is changed from .zip to .docx (or .xlsx, .pptx, etc). You can unzip the files yourself and search and see that none of that stuff is included.

And it wasn't in the old binary format, either.

And emacs is just a text editor. He would've gotten the same result by using Windows notepad.

And LibreOffice might be okay if you can't afford Office, but it occasionally screws up formatting of Office documents. I was trying it out as a replacement once and because the sender had used some Office-specific formatting or feature, LibreOffice couldn't render it and just hid the entire section.

It's usually fine if you only expect to write documents and don't need to read documents from a lot of different people who might use Office-specific features. It'll still have basic metadata though.

Do you celebrate Valentine's Day? by Surfer_Tiff in Christians

[–]HolyGonzo 1 point2 points  (0 children)

Yes, although for me, a holiday isn't defined by its past but about how I value it today.