Jump to content

gizmola

Administrators
  • Posts

    6,110
  • Joined

  • Last visited

  • Days Won

    160

gizmola last won the day on August 3

gizmola had the most liked content!

7 Followers

About gizmola

Contact Methods

  • Website URL
    http://www.gizmola.com/

Profile Information

  • Gender
    Male
  • Location
    Los Angeles, CA USA

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

gizmola's Achievements

Prolific Member

Prolific Member (5/5)

363

Reputation

77

Community Answers

  1. Beyond mac's insights and salient comments, the code snippet you provided tells us nothing, as it is not the code you are using. The only way to gain insight into this is having detailed logging to review when the mailer freezes. I'd also suggest scanning the release notes in regards to the phpMailer releases, to check if there are any Breaking changes you might have missed, or things that are now handled differently between the two versions. There are 2 likely possibilities based on your comments: There are some emails that are causing issues when delivered. The way the code is written (and the environment involved) uses up available resources (network connections, database handles, or other available memory). Many companies use phpMailer so I am doubtful that there is an issue with it that would be trivially obvious, but regardless of that, you need detailed debugging which will be best facilitated by the injection of an object that implements PSR3 as described in the phpMailer source code here. If you don't already have that, here's a bit more on setting that up: After the instantiation of the PHPMailer object, that would involve a call like this: $mail->Debugoutput = new myPsr3Logger; A lot of projects use the well regarded monolog library which allows for logging to be integrated into many different logging systems, but in your case, just insuring it is writing to a log file on your system would be sufficient. As for some trivia, the author of monolog is the same guy who created PHP's dependency management tool Composer. The documentation states that the only log level that will be used is the 'Debug' level.
  2. It is the scripts in the subdirectory named boatlettering. There are 2 I see being called: The image src runs boatNamePreviewImage-new.php load_image2.php gets called when changes to the parameters are made. Obviously things on the server changed and this is probably because your code uses an ancient and long end of life version: php5.6. On top of that, it relies on the imagemagick library, so any issues with the version of imagemagik that supported that old version of php will also cause it to no longer function. I don't see this as being a quick fix, and there is very little people here could do for you, even with the source code, as your existing code is antiquated, and needs to be updated to run under supported versions of php and the imagemagick library, as well as running on a supported operating system, which it most likely did not previously, or now that it has been updated, will no longer support the old code.
  3. That was the question originally posed as I interpreted it. This is why the OP posted interest in the ESP32, which is a line of 32 bit Microcontrollers. They are typically used for IOT projects, and I don't think are a good match for this. A Raspberry pi, Orange Pi, or even a GMTek Mini PC are all a lot more viable given the OP's professed direction in this project, involving an OS capable of running an HTTP server and app server.
  4. The script does no parameter count checking, which isn't a great idea. First thing you would want to do is check $argc == 3. I'm assuming you know that $argv[0] is the script name, so typically you would check the count and display a "usage {$argv[0]} relay# 0|1 [off|on]\n", or something similar if it's not the right count. With that said you stated you wanted to do this with an html page, so probably it would be better to just have a "self posting" form script where you use html to display the controls, and set the 2 parameters based on whatever UI decisions you make. In that case, you would want to get the 2 parameters via the $_POST[] superglobal array, perhaps with html form elements named $_POST['relay'] and $_POST['state'] which you can set to be 0 or 1. You certainly in either case want to do some bounds checking (cast to int or use intval) and insure that the relay is in the range of 0-7. It would also be good if there was a way to determine the pre-existing state of the system. With that said, given the circumscribed set of functions, and purpose of this, I would suggest that you consider the alternative of a board based controller, perhaps with an lcd keypad. With a "mini-pc" you have all the issues of how your web app is going to be displayed, although if your device has wifi, you could design the html/css to be responsive, and control it using a pc or phone. Sounds like a fun and interesting project.
  5. Looking at your code, you should consider the application of DRY (Don't repeat yourself). The entire switch statement, is literally the same code in every case, other than the field name. global $erroredIDArray; global $erroredIDIndexArray; $elem = ''; switch ($i) { case 0: // FIRST NAME $elem = (array_key_exists('firstName', $_POST) && isset($_POST['firstName']) && !is_null($_POST['firstName'])) ? $_POST['firstName'] : ''; if (!is_null($elem) || !$isValidName($elem)) { $isValid = false; array_push($erroredIDArray, 'firstName'); array_push($erroredIDIndexArray, $i); } break; You're also using globals, which you should avoid here. I don't understand what the purpose of the numeric case #'s is, but it's also quite likely you don't need that at all if you create a function to handle this code. I left it out, as it seems to be duplicative. Just mechanically breaking your code out into a function would get you this: function isValid($key, array &$erroredIDArray) { $elem = ''; $elem = (array_key_exists($key, $_POST) && isset($_POST[$key]) && !is_null($_POST[$key])) ? $_POST[$key] : ''; if (!is_null($elem) || !$isValidName($elem)) { array_push($erroredIDArray, $key); // array_push($erroredIDIndexArray, $i); return false; } return true; }
  6. The general principles involved in mac_gyver's valuable comments to you, when applied to classes, include the idea of dependency injection (aka "inversion of control"). If you consider your function, what are the dependencies? The first thing to look for would be objects you are creating internally using new keyword. In your code that is this line: $conn = new PDO(DB_CONNECTION_STR, MYSQL_DB_USER, MYSQL_DB_PASSWORD, MYSQL_DB_PDO_OPTIONS); Rather than creating objects inside the function, you should pass them as parameters. Objects and resources are automatically passed by reference, so you are able to use the class inside the function without limitation, including calling methods that mutate the object. Here's a short video that explains Dependency Injection further. While Dependency injection is an OOP specific design pattern, the philosophy can still be applied to your functional code in most cases. You won't have a DI Container, but you can work around that as long as you understand the idea. So to begin to address many of the things brought up by mac_gyver, I'd expect your function signature to look more like this: function calculateResults(PDO $conn, Poll $pollObj, Array &$resultsCalcArray) { // implementation } You are also using the $_SESSION superglobal. A strong argument can be made that you should also pass the superglobal into your function, rather than simply relying on it's superglobal property. Most frameworks have their own session wrapping class, but you could simply use a parameter like $session, and pass $_SESSION into your function. One reason to do that, is that you can then create unit tests for your function, which would not be possible normally, because $_SESSION only exists in the web context and doesn't exist in the CLI environment. So an alternative would be to do this: function calculateResults(PDO $conn, Poll $pollObj, Array &$session, Array &$resultsCalcArray) { // implementation //... at some point $session['total'] = $total; } Here's a small test script you should be sure you understand now and in the future: <?php /* Illustrating PHP Function parameters. */ class o { private $v = 0; public function inc() { $this->v++; } public function getV() { return $this->v; } } function testParams(o $obj) { for ($x=0; $x < 10; $x++) { $obj->inc(); } return $obj->getV(); } function testParams2($fp, $text) { $text = "1." . $text . PHP_EOL; fwrite($fp, $text); } // Pass Array by Reference function testParams3(Array &$globArray) { array_push($globArray, 'grape'); } // Globally scoped variables $globArray = ['apple', 'banana', 'peach']; $obj = new o(); $r = fopen("/tmp/resource.txt", "w+"); $text = "This is some text."; // $retVal = testParams($obj); echo $retVal . PHP_EOL; echo $obj->getV() . PHP_EOL; echo PHP_EOL; echo "text before testParams2: \n"; echo "\t$text" . PHP_EOL; testParams2($r, $text); rewind($r); $fileData = fgets($r, 4096); echo "File Data:\n"; echo "\t$fileData"; echo "text After testParams2::\n"; echo "\t$text" . PHP_EOL; echo PHP_EOL; echo "Array Before testParams3:\n"; var_dump($globArray); echo PHP_EOL; testParams3($globArray); echo "Array After testParams3:\n"; var_dump($globArray); I posted it to 3v4l so you could experiment with it if you choose.
  7. @LeonLatex This is one of the reasons it is highly advisable that you have scripts that are called via ajax, return json data rather than html markup in most cases. It allows you to separate the data from the markup (which remains in the calling script with the rest of the markup). It also makes it much easier to modify and test your application, as you can focus the php script on returning the data in a structured format that the calling site requires, which can be tested easily with api testing tools like Postman. These days many editors have support for these types of tests through plugins like Thunder client
  8. Right, so the error is telling you that the CA is untrusted. Aside from that, you should not be using the same cert for the client and the server. You need to generate a client cert for the client, and the CN's for each cert should be different. The MySQL manual has a walk through of process: https://dev.mysql.com/doc/refman/5.7/en/creating-ssl-files-using-openssl.html
  9. This is a problem you will encounter when you have code in production and need to update it. You'll need some way to "cache bust" files that users have already cached locally or they will continue to use the old version. For development, if you develop using Chrome, you can install an extension. I have used this one for a long time and it is safe and reliable: https://chromewebstore.google.com/detail/clear-cache/cppjkneekbjaeellbfkmgnhonkkjfpdn Make sure you set it up to pin the button to the extension window, and then when you need to test, you can click it will clear cached items for the site you are working on.
  10. You can specify either the width or the height for an image, and it will size to that. Generally speaking you want to pick one or the other, and allow the other dimension to be sized relative to the one you specify, otherwise the browser will attempt to fit the image which if the ratio of width/height doesn't match will cause the image to skew. What maxxd pointed out, is that the browser will download the full image either way, so if the image is much larger than the place where you are using it, clients will still have to pull down the full size image, which makes things slower and eats up more of your bandwidth. One very useful css property to be aware of is object-fit. I frequently use object-fit: cover in styles for images, although there are other options that might be better for your particular use cases. It's also very useful for backgrounds, as you can do things like this: .canvas__bg-img { height: 100%; width: 100%; object-fit: cover; opacity: 0.15; }
  11. Not according to what you originally stated. You stated that for every request you wanted to "issue a reply quickly and start a timer." It was never clear if this was just a means to an end or not, because you didn't explain the problem you are trying to solve. What it does sound like at this point, is that you are trying to create your own home grown IDS or WAF, and you already got a suggestion from me, and a suggestion from requinix. For the most part people use fail2ban to drop annoying ssh bots and other similar port based traffic by bots and script kiddies trying brute force password attacks. It's written in Python, so it's not exactly light weight either, but it also has a simpler job in practice -- just count a small number of bad attempts and block the IP. That isn't going to work for something more sophisticated. This is why I suggested looking at OSSEC, and if it's more a WAF you want there are bunch of self hosted ones that also have FOSS versions like Safeline, Modsecurity and Bunkerweb.
  12. It appears that writing PHP event handlers is simple and works well, and people have been using fullcalendar with PHP for some years now without issue. It's a fairly standard approach to wiring together js UI with PHP backend. Hopefully it's clear that you send and receive data in json format.
  13. But what is the 1st task, and how is it connected to this? My kneejerk reaction is that there are FOSS IDS tools like OSSEC you should look into. Even if you continue to go forward, an asynchronous approach is going to be better. When your site is inevitably accessed by bots/spiders, the overhead of spawnng a php process for every request is likely one that you will regret.
  14. What is the application or problem you are trying to solve? This has all the hallmarks of an X/Y problem. What I can deduce: Some event occurs and some action is taken A 2nd action should be taken some time later (60 seconds in your case) However you don't want action 2 to occur in some circumstances for reasons undisclosed You've used the phrase: From your description, every request is immediately handled. Without knowing the purpose of this 2nd action, it's difficult to provide advice, but the obvious problem is that you want the 2nd action to be aware of the first action. Rather than a dumb process blocking for 60 seconds, it appears you want a process that will be created with a future event datetiime (1 minute in the future) If before it completes, a new event #1 comes in, you modify the expiration datetime and set it to 1 minute from the event Another possible low tech way of handling this would be to have process 2 implement a semaphore/lock file that is checked for when process 2 is run. Shared memory and IPC semaphores can be helpful for something like this. With that said, anytime you utilize a mechanism that relies on a single server architecture the scheme is inherently non scalable. This is where things like queues or databases typically come into play. Using some in memory server like redis is often a better platform.
  15. That wasn't the point of the example code, and ... it's meaningless example code. The point was to clarify how ticks function. Without enclosing the code in a block, the results will probably not be what is expected. Hope this has helped you. If you are doing something interesting with this, it would be great to get a follow up.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.