Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Ranzear
Jul 25, 2013

I'm bored on a Saturday too, let's do some casual golfing:

code:
<?php
$sounds = array("p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y", "a", "e", "I", "o", "u", " " , "p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y", "w'", "y'", "rgh");
for ($i=0; $i < 21*5*25; $i++) {
	echo ($syl = $sounds[$i%21] . $sounds[21+floor($i/21)%5] . $sounds[21+5+floor($i/(21*5))%25] . "<br>") && (strpos($syl, "ow") || strpos($syl, "uw")) ? "" : $syl;
}
2541 results, right?

Of course you could inline the array three times to make it just one line, and of course you could chop variable names down, but I think this is as logically compressed as it can get. I would bet there's a way to arrange ow and uw combinations to fall in a pattern in the encoding that you could exclude them mathematically, but I don't think that'd be much simpler in the end (it would certainly be faster than string comparison if you needed it stupid fast though).

Fun fact: You can modulo encode any number of dimensions of integer coordinates as long as they have fixed bounds per dimension, up to whatever size of integer you can store. You can then perform operations on the integers themselves rather than needing to store coordinates. This is great for stuff like n-dimensional chessboards.

Ranzear fucked around with this message at 22:20 on Jan 27, 2019

Adbot
ADBOT LOVES YOU

Kraus
Jan 17, 2008

Ranzear posted:

I'm bored on a Saturday too, let's do some casual golfing:

code:
<?php
$sounds = array("p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y", "a", "e", "I", "o", "u", " " , "p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y", "w'", "y'", "rgh");
for ($i=0; $i < 21*5*25; $i++) {
	echo ($syl = $sounds[$i%21] . $sounds[21+floor($i/21)%5] . $sounds[21+5+floor($i/(21*5))%25] . "<br>") && (strpos($syl, "ow") || strpos($syl, "uw")) ? "" : $syl;
}
2541 results, right?

Of course you could inline the array three times to make it just one line, and of course you could chop variable names down, but I think this is as logically compressed as it can get. I would bet there's a way to arrange ow and uw combinations to fall in a pattern in the encoding that you could exclude them mathematically, but I don't think that'd be much simpler in the end (it would certainly be faster than string comparison if you needed it stupid fast though).

Fun fact: You can modulo encode any number of dimensions of integer coordinates as long as they have fixed bounds per dimension, up to whatever size of integer you can store. You can then perform operations on the integers themselves rather than needing to store coordinates. This is great for stuff like n-dimensional chessboards.

Whoa, I hadn't thought of that! And yeah, that results number is correct! I took a glance through your results and nothing looked like it was missing.

And yeah, I did realize I could glom the array onto the boolean that's in bit 1 of the ternary. I just wish that I could use the truncated ternary, but when you use it after an echo, it echoes "1" when bit 1 is true, so no bueno. I'm definitely gonna give this a shot too! I came to programming from linguistics instead of math, so mathematical solutions don't immediately jump out at me. Thanks!

Ranzear
Jul 25, 2013

Kraus posted:

I came to programming from linguistics instead of math, so mathematical solutions don't immediately jump out at me.

Just beware of tailored solutions like this. Most would have done a fixed shift for each coordinate to encode into one integer (each dimension gets n bits), but mine are arbitrary to make a continuous set that can be iterated over.

Also keep in mind that code golf code is never good code. You should keep the arrays separate for clarity of purpose, and then generalize the implementation using the length of each so you don't have to muck about with literals in the code just to alter any of the arrays:

code:
<?php
$onsets = array("p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y");
$nuclei = array("a", "e", "I", "o", "u");
$codas = array(" " , "p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y", "w'", "y'", "rgh");

$oc = count($onsets);
$nc = count($nuclei);
$cc = count($codas);

for ($i=0; $i < $oc*$nc*$cc; $i++) {
	$syl = $onsets[$i%$oc];
	$syl .= $nuclei[floor($i/$oc)%$nc];
	$syl .= $codas[floor($i/($oc*$nc))%$cc]."<br>";
	echo (strpos($syl, "ow") || strpos($syl, "uw")) ? "" : $syl;
}
I was also concerned that strpos( ) could return 0, which would be falsey and fail to throw something out if it started with 'uw' or 'ow', but neither of those appear in your onsets. If they did, you'd have to more strictly check.

Ranzear fucked around with this message at 01:48 on Jan 28, 2019

Kraus
Jan 17, 2008

Ranzear posted:

Just beware of tailored solutions like this. Most would have done a fixed shift for each coordinate to encode into one integer (each dimension gets n bits), but mine are arbitrary to make a continuous set that can be iterated over.

Also keep in mind that code golf code is never good code. You should keep the arrays separate for clarity of purpose, and then generalize the implementation using the length of each so you don't have to muck about with literals in the code just to alter any of the arrays:

code:
<?php
$onsets = array("p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y");
$nuclei = array("a", "e", "I", "o", "u");
$codas = array(" " , "p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "w", "r", "l", "y", "w'", "y'", "rgh");

$oc = count($onsets);
$nc = count($nuclei);
$cc = count($codas);

for ($i=0; $i < $oc*$nc*$cc; $i++) {
	$syl = $onsets[$i%$oc];
	$syl .= $nuclei[floor($i/$oc)%$nc];
	$syl .= $codas[floor($i/($oc*$nc))%$cc]."<br>";
	echo (strpos($syl, "ow") || strpos($syl, "uw")) ? "" : $syl;
}
I was also concerned that strpos( ) could return 0, which would be falsey and fail to throw something out if it started with 'uw' or 'ow', but neither of those appear in your onsets. If they did, you'd have to more strictly check.

Dude, oh yeah, this is for funsies, so I'm intentionally breaking all kinds of good practices just for shits and giggles. I promise my professional code looks nothing like this.

Edit: Yeah, I'm abusing the fact that strpos can't possibly return 0.

Kraus fucked around with this message at 01:54 on Jan 28, 2019

Ranzear
Jul 25, 2013

Right, but a little bit of golfing can help. This reduced three ugly nested loops to just one, reduced literals in the block, split concatenation over more than one line. and avoided unnecessary assignments. I would call the functional parts of that final version good enough for the kind of work I do.

Anyway, because I hate string comparison, here's the changes for a true turbo(nerd) version:

code:
$codas = array(" ", "p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "r", "l", "y", "y'", "rgh", "w", "w'");
code:
	echo (floor($i/$oc)%$nc >= 3 && floor($i/($oc*$nc))%$cc >= 23) ? "" : $syl;
Just do the same divide-and-modulo to get the index and check the combo isn't restricted. Easiest to just move the restricted particles to the end so you only have to do one >= compare.

I've put literals back in the block again but ¯\_(ツ)_/¯ you already had two there for strpos anyway.

Ranzear fucked around with this message at 02:14 on Jan 28, 2019

Kraus
Jan 17, 2008

Ranzear posted:

Right, but a little bit of golfing can help. This reduced three ugly nested loops to just one, reduced literals in the block, split concatenation over more than one line. and avoided unnecessary assignments. I would call the functional parts of that final version good enough for the kind of work I do.

Anyway, because I hate string comparison, here's the changes for a true turbo(nerd) version:

code:
$codas = array(" ", "p", "t", "q", "'", "b", "D", "tlh", "ch", "Q", "j", "S", "H", "v", "gh", "m", "n", "ng", "r", "l", "y", "y'", "rgh", "w", "w'");
code:
	echo (floor($i/$oc)%$nc >= 3 && floor($i/($oc*$nc))%$cc >= 23) ? "" : $syl;
Just do the same divide-and-modulo to get the index and check the combo isn't restricted. Easiest to just move the restricted particles to the end so you only have to do one >= compare.

I've put literals back in the block again but ¯\_(ツ)_/¯ you already had two there for strpos anyway.

Huh, yeah, that makes a hell of a lot of sense. And yeah, those arrays were organized in a way a linguist would do it, from the top left corner of a consonant chart, to the lower right.

stoops
Jun 11, 2001
I'm reading a txt file and the array looks something like this:

code:
[
	(int) 0 => 'Energy (MeV), Effective Efficiency for gamma= -2',
	(int) 1 => '2.00000      0.65605279',
	(int) 2 => '2.10000      0.52212562',
	(int) 3 => '2.20000      0.44027946',
	(int) 97 => 'Energy (MeV), Effective Efficiency for gamma= -3',
	(int) 98 => '2.00000      0.59334933',
	(int) 99 => '2.10000      0.48547332',
	(int) 100 => '2.20000      0.41917096',
	(int) 101 => '2.30000      0.37441758',
	(int) 102 => '2.40000      0.34226023',
]
That Energy string could be different, but I need a way to group all the data, after it finds a string, to another array.

I know I can loop thru this array, but I wasn't sure how to group the data after finding the string.

(i don't need to keep the order of the keys in order)

my desired output would be something like:

code:
array (0=> (int) 0 Energy (MeV), Effective Efficiency for gamma= -2,
	(int) 1 =>2.00000      0.65605279',
	(int) 2 =>2.10000      0.52212562',
	(int) 3 => 2.20000      0.44027946',
),
array (1 => '(int) 97 Energy (MeV), Effective Efficiency for gamma= -3',
	(int) 98 => '2.00000      0.59334933',
	(int) 99 => '2.10000      0.48547332',
	(int) 100 => '2.20000      0.41917096',
	(int) 101 => '2.30000      0.37441758',
	(int) 102 => '2.40000      0.34226023',
),
//etc. 
Thanks, I appreciate any help or links.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Don't know if this helps, been a while since I've been in PHP land, but I googled explode into multi dimensional array and got this SO:
https://stackoverflow.com/questions/21463420/php-explode-and-assign-it-to-a-multi-dimensional-array

Looks like kind of what you're looking for, if you replace the OPs line number with your Energy entry.

Mr Crucial
Oct 28, 2005
What's new pussycat?
A newbie question: when should I stop developing frontends in PHP and switch over to something like Vue or React?

I’ve been creating a site using Laravel which has been great for getting all the backend functionality that I want, but for the front end I’ve been using basic views using Bootstrap with a dash of jquery thrown in when I need something a bit more dynamic (datatables, autocomplete lookups etc).

As I’m adding more functionality in I’m finding that the jquery libraries I’m using aren’t cutting it for me and I’m coming to the conclusion that it’s time to learn a front end framework. But it seems to me that React etc all expect to be handling all of the front end as a single page app and I can’t just replace my jquery stuff with equivalent React components and call it a day, or at least that wouldn’t be optimal. Nor do Bootstrap components appear to play nicely when used within React components, although another framework like Bulma looks like it might work a bit better.

What to do?

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Mr Crucial posted:

But it seems to me that React etc all expect to be handling all of the front end as a single page app and I can't just replace my jquery stuff with equivalent React components and call it a day, or at least that wouldn't be optimal.

You've correctly identified the main problem with a lot of framework code - it's often so highly opinionated that it's effectively all or nothing. Vue seems to be the non-opinionated choice when you need reusable components that render client-side. I've had some luck with it, but I don't speak it idiomatically and haven't used many third party libraries for it.

If you can talk more about the specific problems you're struggling to solve with jQuery, we might be able to provide more help. It remains as a good tool for simple interactivity, but keep in mind that it can't interact at all with React and Vue components because of how those libraries operate.

McGlockenshire fucked around with this message at 19:21 on Mar 16, 2019

Mr Crucial
Oct 28, 2005
What's new pussycat?

McGlockenshire posted:

If you can talk more about the specific problems you're struggling to solve with jQuery, we might be able to provide more help. It remains as a good tool for simple interactivity, but keep in mind that it can't interact at all with React and Vue components because of how those libraries operate.

I'm building what is basically a big CRUD up for managing some old historic data. I've been writing an API as part of this but my views are driven by Eloquent queries in my controllers, the API is mainly for bulk-uploading stuff from Excel or CSV. A couple of specific issues I'm having:

I've been using MDBootstrap datatables on some of my index views so I can do some basic searching and sorting, but as the results get bigger it takes longer and longer to actually draw the table. The worst culprit currently has about 1,000 records but it could eventually end up with 10 times that amount. I know what I need to do is retrieve the results from the API and enable some sort of pagination, but I'm unsure of the best way to do this. MDB supports APIs for datatables but the documentation is really poor and I haven't figured out how to get it working yet, nor does it support API level pagination from what I can tell.

Another example is using autocomplete on fields to establish relationships, so I can do a text-lookup based on 'name' or some other meaningful attribute but actually build the relationship built on ID in a related hidden field. I have some custom code that does this as well as clearing the relationship if I delete the field. I haven't seen any pre-built components that can do this.

I'm sure these aren't difficult things for a veteran web coder but for my part I don't want to start down the wrong path and end up wasting a lot of time learning something like React or Vue if there's a better way.

bigmandan
Sep 11, 2001

lol internet
College Slice

Mr Crucial posted:

A newbie question: when should I stop developing frontends in PHP and switch over to something like Vue or React?

I’ve been creating a site using Laravel which has been great for getting all the backend functionality that I want, but for the front end I’ve been using basic views using Bootstrap with a dash of jquery thrown in when I need something a bit more dynamic (datatables, autocomplete lookups etc).

As I’m adding more functionality in I’m finding that the jquery libraries I’m using aren’t cutting it for me and I’m coming to the conclusion that it’s time to learn a front end framework. But it seems to me that React etc all expect to be handling all of the front end as a single page app and I can’t just replace my jquery stuff with equivalent React components and call it a day, or at least that wouldn’t be optimal. Nor do Bootstrap components appear to play nicely when used within React components, although another framework like Bulma looks like it might work a bit better.

What to do?

As mentioned already, Vue is very flexible with how much of the framework you use. You can start with just a few pages at a time and then gradually change into a SPA if you want to. You can also just use components where needed and leave the rest as is.

kiwid
Sep 30, 2013

I asked this on Laracasts but didn't get any replies. Hoping someone can help me here.

My question is: How do I read source code that eventually leads back to an interface?

Whenever I'm trying to figure out how something works and it leads back to an interface, I get lost.

For example, I was trying to figure out how the `Str::plural()` method works.

Step 1: Look up the `Illuminate\Support\Str` class.
Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Str.php

Step 2: Find the `plural()` method.
Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Str.php#L278-L281

Step 3: See that it's using a `Pluralizer` class so find that.
Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Pluralizer.php

Step 4: Find the `plural()` method on the `Pluralizer` class.
Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Pluralizer.php#L65-L74

Step 5: See that it's using Doctrine's Inflector class so find that.
Done: https://github.com/doctrine/inflector/blob/master/lib/Doctrine/Inflector/Inflector.php

Step 6: Find the `pluralize()` method on the `Inflector` class.
Done: https://github.com/doctrine/inflector/blob/master/lib/Doctrine/Inflector/Inflector.php#L502-L505

Step 7: See that it's calling an `inflect()` method on a `pluralizer` object so try to find what the `pluralizer` object is.
Done: It appears to be some type of instance of a `WordInflector` interface.

Now how do I go from here? I have no idea what the object is being passed that implements the `WordInflector` interface.

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
The main problem here is the you're looking at the source code of the latest version of the Inflector which laravel does not use, which is why you can't find what the concrete WordInflector it's using. A quick look at it's composer.json reveals it has a ^1.1.0 dependency on the Inflector, so you could start there (or at 1.3, you'd have to look at the composer.lock file to get the exact version they're assuming).

Looking at the 1.3 release (though I'm not fully sure it uses this, or an older version still, you'd have to check) should make more sense: https://github.com/doctrine/inflector/blob/1.3.x/lib/Doctrine/Common/Inflector/Inflector.php

It should be noted that the new version of the Inflector that is being designed does not have static methods similar to the old version which would be a clue you weren't looking at the right code.

Master_Odin fucked around with this message at 04:30 on Apr 12, 2019

kiwid
Sep 30, 2013

Master_Odin posted:

The main problem here is the you're looking at the source code of the latest version of the Inflector which laravel does not use, which is why you can't find what the concrete WordInflector it's using. A quick look at it's composer.json reveals it has a ^1.1.0 dependency on the Inflector, so you could start there (or at 1.3, you'd have to look at the composer.lock file to get the exact version they're assuming).

Looking at the 1.3 release (though I'm not fully sure it uses this, or an older version still, you'd have to check) should make more sense: https://github.com/doctrine/inflector/blob/1.3.x/lib/Doctrine/Common/Inflector/Inflector.php

It should be noted that the new version of the Inflector that is being designed does not have static methods similar to the old version which would be a clue you weren't looking at the right code.

You're right I should have clued into the fact that Laravel was using a static method but knowing Laravel I figured it was using some obscure "magic" somewhere. My bad.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

kiwid posted:

You're right I should have clued into the fact that Laravel was using a static method but knowing Laravel I figured it was using some obscure "magic" somewhere. My bad.

Hah! Based on my experience the fact that you're asking these questions already puts you head and shoulders above 95% of the php programmers I've interacted with.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

What are some common ways to refactor poo poo like this? Imagine functions.php with 500 functions just like this

code:
function IsActiveEmp($EmpID) {
  $link=mysqli_connect("database","user","password") or die(mysqli_error());
  $db=mysqli_select_db("erp",$link) or die(mysqli_error());
  $query="SELECT Serial FROM TbfEmployee WHERE EmpID=".$EmpID." AND Active<>0;";
  $result=mysqli_query($query,$link) or die(mysqli_error());
  if(mysqli_num_rows($result)>0) {
    return true;
  } else {
    return false;
  }
}

spiritual bypass
Feb 19, 2008

Grimey Drawer
Create an Employee class with an isActive() method that gets populated from the start when you load it from an EmployeeStorage interface via the GetById(int) method. You'll implement this interface several times over with a SQL version sitting at the bottom, then several decorators on top to handle things like validation and caching.

Or at least that's how I build business software.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

rt4 posted:

Create an Employee class with an isActive() method that gets populated from the start when you load it from an EmployeeStorage interface via the GetById(int) method. You'll implement this interface several times over with a SQL version sitting at the bottom, then several decorators on top to handle things like validation and caching.

Or at least that's how I build business software.

Object-Relational Mapping (ORM) is probably what OP should Google to find out more

Django has a great one for the python world: https://docs.djangoproject.com/en/2.2/topics/db/queries/

Hibernate is an option over in Java land

There's probably a bunch of different ones for PHP but I haven't done PHP in forever so not sure what is preferred there these days :) Maybe Laravel? https://laravel.com/docs/5.0/eloquent

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Eloquent is ActiveRecord, which breaks the Single Responsibility Principle, the single most important thing to understand when doing serious OO stuff. That article is about Rails, but it applies equally to any ActiveRecord implementation.

Instead, consider a Data Mapper, like Doctrine.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
I am building an IIS-based PHP web site on AWS located in three regions across the globe. On the back end I have a trio of database servers replicating across those regions and I want each pool of web servers to access their local database node above all the others.

I have a single DFS share that spans the three regions so I can make a single code push to the DFS share and all web servers in each of the three pools gets an update.

So I have created a test Config.php file that looks like this:

code:
<?php
echo "Hello<br>";

$OS = getenv('OS');
echo "OS: ".$OS."<br>";

$InstanceAZ = getenv('EC2-InstanceAZ');

if ($InstanceAZ == 'us-west-2a') {$serverName = "10.1.1.50";} 
if ($InstanceAZ == 'us-west-2b') {$serverName = "10.1.1.50";} 
if ($InstanceAZ == 'us-east-1d') {$serverName = "10.2.1.50";} 
if ($InstanceAZ == 'us-east-1e') {$serverName = "10.2.1.50";} 
if ($InstanceAZ == 'us-east-2a') {$serverName = "10.3.1.50";}
if ($InstanceAZ == 'us-east-2b') {$serverName = "10.3.1.50";}
     echo "AZ: ".$InstanceAZ."<br>";
     echo "DB Server: ".$serverName."<br>";

?>
Where EC2-InstanceAZ is a windows system environment variable set at launch via powershell. As it stands right now, I can RDP into a web server, open a command prompt and run the script and it returns

Hello
OS: Windows_NT
AZ: us-west-2a
Server: 10.1.1.50

as expected. But when I run the script by accessing it in IIS I get

Hello
OS: Windows_NT
AZ:
Server:

Somehow PHP is not able to fetch EC2-InstanceAZ from the list of system variables inside IIS even though it can pull a different system variable. Does anyone have an idea?

nielsm
Jun 1, 2009



At what point is your environment variable getting set?

As far as I understand IIS architecture, you run IIS as a system service, which does not inherit any environment, and IIS in turn runs workers such as PHP FastCGI in an application pool, which does not inherit any environment either. So you'd have to configure the environment at the application pool level.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

nielsm posted:

At what point is your environment variable getting set?

As far as I understand IIS architecture, you run IIS as a system service, which does not inherit any environment, and IIS in turn runs workers such as PHP FastCGI in an application pool, which does not inherit any environment either. So you'd have to configure the environment at the application pool level.

These are AWS EC2 instances, and upon launch they pull AZ information from http://169.254.169.254/latest/meta-data/placement/availability-zone and shoves it into a system variable called EC2-InstanceAZ. I agree about IIS running as a system service, and fast CGI running in a different environment, but System variables should be available to all sessions (as opposed to user variables that are specific to specific sessions).



What is bugging me is that I can pull other system variables (like OS, DriverData) but EC2-InstanceAZ, EC2-InstanceId, etc chokes.

Agrikk fucked around with this message at 20:33 on Dec 9, 2019

itskage
Aug 26, 2003


Agrikk posted:

I am building an IIS-based PHP web site on AWS

But why??

Pile Of Garbage
May 28, 2007



Agrikk posted:

These are AWS EC2 instances, and upon launch they pull AZ information from http://169.254.169.254/latest/meta-data/placement/availability-zone and shoves it into a system variable called EC2-InstanceAZ. I agree about IIS running as a system service, and fast CGI running in a different environment, but System variables should be available to all sessions (as opposed to user variables that are specific to specific sessions).



What is bugging me is that I can pull other system variables (like OS, DriverData) but EC2-InstanceAZ, EC2-InstanceId, etc chokes.

A few things:

  • Do the variables at least show up in the list displayed by phpinfo()?
  • Are the variables visible in the registry under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment?
  • Is IIS being restarted after the variables are set (A child process environment block can only be modified by a parent when the child process is created, therefore changes to parent environment block won't effect the child unless it's restarted)?

itskage posted:

But why??

Also this, especially the multi-AZ DFS :lol:

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Pile Of Garbage posted:

A few things:

  • Do the variables at least show up in the list displayed by phpinfo()?
  • Are the variables visible in the registry under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment?
  • Is IIS being restarted after the variables are set (A child process environment block can only be modified by a parent when the child process is created, therefore changes to parent environment block won't effect the child unless it's restarted)?

The variables do not show up in phpinfo() and they are in the list under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and IIS is being restarted.

itskage posted:

But why??

quote:

Also this, especially the multi-AZ DFS :lol:

Because I have some spare time, and the free resources with which to goof off . And most importantly, because I can. :D

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


I recently discovered Psalm and I really like it. I put its generic notation into our custom orm and now it is giving the right autocompletes & type checking. Plus all the issues a static analyzer can find.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
It turned out to be an IIS thing, not a PHP thing, but the answer was to turn on "Load User Profile" for the application pool.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Agrikk posted:

The variables do not show up in phpinfo() and they are in the list under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and IIS is being restarted.



Because I have some spare time, and the free resources with which to goof off . And most importantly, because I can. :D

Right but for your own sanity why not use a Linux box for PHP and have environment variables just available to you without stuffing around?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

a hot gujju bhabhi posted:

Right but for your own sanity why not use a Linux box for PHP and have environment variables just available to you without stuffing around?

I've been a windows guy for decades now. While I can fumble my way around a linux box and make it work, I am way more familiar with the idiosyncrasies of WISP than LAMP (present issue aside). I just don't find Linux boxes intuitive. :shrug:

itskage
Aug 26, 2003


If you're just playing around to learn, you'll get way more bang for your buck out of learning a better setup.

Depends on what your goals are I guess.

e: I posted a guide to running php+nginx on windows in here a bit ago if that's of any interest. But that's really for local dev. Production should go on linux.

itskage fucked around with this message at 06:48 on Dec 13, 2019

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Eh, I hear what you are saying and ordinarily I recommend going LAMP to learn PHP, but in this case I’m building a Rube Goldberg setup intentionally.

As it turns out, the back-end is actually a set of databases in three regions including Aurora Postgres, RDS SQL Server, SQL Server Availability Groups and stand-alone but load balanced SQL on EC2. All serving up the same data sets.

So PHP on IIS with the web sites running off of DFS is hardly the weirdest design decision I have going on here. :D

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Agrikk posted:

I've been a windows guy for decades now. While I can fumble my way around a linux box and make it work, I am way more familiar with the idiosyncrasies of WISP than LAMP (present issue aside). I just don't find Linux boxes intuitive. :shrug:

These days it's basically just a matter of pulling a docker image and starting it up, I'd really encourage you to take a look into it just for the sake of learning some cool new poo poo that will make your life much easier.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Looking for memcached help now. Same app as above...


So I have a SQL Server table that is [userID],[timestamp],[data1] and I have a PHP-based web application that returns [data1] for all [timestamp] for a specific [userID]. It returns in a tabular format:

http://folding.rainwalk.net/UserHourlySummary.php?UserName=Agrikk&TeamNumber=33

I'm experimenting with AWS Elasticache to speed up database performance and I'm wondering how to make it all work.

I understand the basic mechanism with PHP that you write a check to see if the key exists in cache then use that, and if it doesn't then fetch it from a database and also copy it into cache.

My question is more around how memcached "knows" that data in the database has been updated.

If the above table receives INSERTS at a rate of one batch every 60 minutes, and data older than 14 days is purged, what is the optimal way to fetch the data in PHP so that data lives in cache for 14 days and what is the optimal way to retrieve the data during page load so that it pulls the majority of the data from cache and the remainder from the database?

Right now my PHP page runs a SELECT statement and then uses a

code:
while( $row = sqlsrv_fetch_array( $stmt) ) {
    echo "<td>".$row[0]->format("Y-m-d H:i")."</td><td>".number_format($row[1])."</td><td>".number_format($row[2])."</td></tr>";
}
statement to build the table for viewing. But a while statement pulls all records in a single batch and I don't see a method to do a check for cache-vs-database existence of each row of data.

What is the best practice here?

Agrikk fucked around with this message at 02:22 on Dec 24, 2019

NotWearingPants
Jan 3, 2006

by Nyc_Tattoo
Nap Ghost
I haven't used PHP for a while and I'm doing a Symfony video tutorial and the guy keeps writing function calls like
code:
doSomething( id: 4, value: 'text string');
This is a syntax error for me. So after thinking this was some new syntax and searching fruitlessly for examples I am like 95% sure it's something his editor is doing for display and isn't the actual code.

Please correct me if I am wrong.

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
That's an IDE thing, PHP does not support named parameters unfortunately.

PHPStorm refers to it as inlay hints.

Good Sphere
Jun 16, 2018

My work is having me start in on something on the web that is real time, amongst many users. This could be a chat or a game. I'm only starting to become familiar with this kind of development, so I first looked into Ratchet since I know a bit about PHP. I foolishly installed it onto our shared hosting. I learned a lot; including installing and messing with stuff in bash. But it doesn't allow websockets or listening ports.

Is Ratchet still in use? Any information on popular services that use it? Should I be using Symfony instead? What should I be using?

What should I be using as a VPS just to get started?

spiritual bypass
Feb 19, 2008

Grimey Drawer
Use any VPS you like. Check AwfulMart for some decent hosts with goon discounts.

PHP is not well suited to long-running processes. Writing the main app in PHP is usually not a terrible idea, but use something else for the websocket. Javascript is a popular choice, although it's a massive footgun. I'd pick Go.

Pile Of Garbage
May 28, 2007



Good Sphere posted:

What should I be using as a VPS just to get started?

If your employer is paying the bill then just go with AWS.

Adbot
ADBOT LOVES YOU

Good Sphere
Jun 16, 2018

Thanks for the suggestions. They got Kamatera Ubuntu server with nginx. I logged into Kamatera's dashboard for the account, and ssh'd in Mac OS's Terminal. I don't know where to even start. I'm so used to using an ftp client and the like, and I don't even know how with this yet, or if I should. A new frontier for me.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply