I’m kind of excited that we moved the first site onto a new server setup at Cogneato. I had worked off and on on the setup for months before we finally went forward with it. It brings a new OS, new host, new software, and a number of other changes to our previous setup.
Continue reading post "New server setup at Cogneato"php posts page 2
Today I learned that PHP’s mkdir()
with the octal permission argument apparently doesn’t support any value other than 0
in the leftmost octal spot (where setuid, setgid, and sticky bit go).
FastCGI and “Primary Script Unknown”
If you’re routing requests for script file names through FastCGI, and don’t have some rule to catch requests for unknown scripts, you might find errors like:
Got error 'Primary script unknown\n'
in your error log.
Continue reading post "FastCGI and “Primary Script Unknown”"PHP zend_mm_heap corrupted error
We were getting errors on our server where certain pages or even sites would occasionally or frequently show errors for no apparent reason.
Continue reading post "PHP zend_mm_heap corrupted error"PHP: Fallback for old constructor style
In versions of PHP before 5, constructors were functions with the same name as their class. PHP 5 introduced the __construct()
unified name, and has deprecated the old style in PHP 7. Cogneato still has code remnants from long ago, with the old style. I recently worked on improving the compatibility of our old code with PHP 7.
HTTP 2 on Ubuntu 18.04 with Apache and PHP
I recently got h2 (HTTP 2.0) running on my server.
Continue reading post "HTTP 2 on Ubuntu 18.04 with Apache and PHP"Server upgrade: Ubuntu 18.04
I’ve finally updated my server to Ubuntu 18.04 using do-release-upgrade
.
10k Apart: Deployed
My 10k Apart entry was finally deployed and can be seen at its Azure URL, though it’s not in their gallery yet. There were problems deploying it, and it took several tries and back and forths with Aaron Gustafson himself to get it working.
Continue reading post "10k Apart: Deployed"Quick regex to strip html tags
Recently, I needed to strip some HTML tags from some data. The goal was to make a field in a database that was a WYSIWYG text area into plain text content that could go inside a link. I did it using a simple regex of /<\/?[^>]+>/
to find the tags so I could replace them with an empty string. In PHP, this looked like:
$string = preg_replace('/<\/?[^>]+>/', '', $string);
This is perhaps a naïve implementation, but it served my purposes fine. Of course, I had totally forgotten about PHP’s built in strip_tags()
function, but on comparing it, it also seems to not do exactly what I want. For instance, it seems to get rid of the content of <a>
tags.
Sending email attachments with PHP `mail`
I recently had to set up a PHP script to send an email with an attachment. With the current version of our CMS, we have swiftmailer available, which would make this easy, but for this site, I didn’t have it easily available. I considered bringing it in, but since this was just a simple script, I decided to give a go at doing it directly with PHP’s built in mail()
function. I found an answer on StackOverflow to guide me. Many respondents to that question recommended just using a library, but the answers that didn’t seemed reasonable.
It took me a number of failed attempts to get the headers and line-breaks just right so that both the email message and attachment sent properly, but I got it working. The code of my solution was fairly specific to the application, so I’ve modified it to make it more generically applicable for this post. The (untested but generic) variant of the solution looks like:
Continue reading post "Sending email attachments with PHP `mail`"