Jump to content

gizmola

Administrators
  • Posts

    5,954
  • Joined

  • Last visited

  • Days Won

    145

Community Answers

  1. gizmola's post in aws elastic beanstalk permissions and ownership. was marked as the answer   
    You are running shell scripts that set environment variables for some reason. Maybe these are ubuntu things, but they aren't important to the basic workings of the system unless there is something happening in the apache startup script. I personally use amazon linux for all my ec2 instances, since they insure it works well with ec2 and they come preconfigured with package repos maintained and tested by amazon.
     
    At any rate, what I feel is the best practices in this situation is that you have a separate user|group combination for apache. However, apparently that is webapp currently, so I would not look into trying to change it. Check your apache httpd.conf file (should be somewhere in /etc or a directory underneath it) and see who the user/group is.
     
    To check out the entry for webapp, cat the /etc/passwd file and see what the entry for the webapp user is. I don't know why there wouldn't be a group there.
     
    In the apache httpd.conf file there is an entry for the user/group apache will run as. That should be webapp in this case.
     

    User webapp Group webapp
  2. gizmola's post in Php page image with text rewritten to function but... was marked as the answer   
    You should not be outputting an image header in a script that is simply creating an image and writing it to disk. Remove the
     

    Header ("Content-type: image/jpeg"); The other thing to look into is the path: 

    imagejpeg($image, 'vda-images/'.$n1.'.jpg', 80); Make sure that whatever process is running this php code has rights to rwx the vda-images directory.
  3. gizmola's post in Can a saved vagrant box handle a change in ISP ? was marked as the answer   
    What you want to do is change your network from public_network to "private_network". This will used the Nat adapter.
     
    Make sure the network is something that is unlikely to conflict with your home or work network. Something like '192.168.77.x'
  4. gizmola's post in what to do now ?! was marked as the answer   
    Learning to program can easily become a rabbit hole.
     
    Programming exists to create applications and systems that solve a problem or facilitate a business.
     
    The simple answer is, in order to progress as a programmer you need to actually program.
     
    Write down a design specification for something you want to build, and build it. Along the way you will need to problem solve. You will need to learn things you don't understand adequately at present, and you will fail, and in the process learn how to debug and become more competent.
     
    Let's say you read a bunch of books on carpentry, but never try to build anything? Would you hire that person to make you cabinets for your house?
     
    I know many developers who are starting out, who build things simply to have a portfolio showing what they can do.
     
    When I first started as a programmer, I made some silly applications that didn't do much, but in each case I learned a great deal. Eventually I created a freeware menu system (this was back in the days when DOS PC computers dominated the marketplace) and my software allowed you to create some simple text files that would be read in, and allow a user to navigate through the options and start programs. There were many such programs available at the time, but I built mine anyways, and used it on my computer and installed it on my parents computer.
     
    In creating it, I realized that I had a need to utilize record structures, linked lists, windowing libraries and file io. It required me to learn a lot of things and as a result I advanced as a programmer and this experience lead directly to a job that essentially started my professional programming career.
     
    With each project you learn more and become a more capable developer.
  5. gizmola's post in Please explain "FOR" loops was marked as the answer   
    For loops are just generic conditional control structures. The php syntax was borrowed from c, and it's common to many languages.
     
    In your example there's a problem because all php variables have to start with a '$'. But if we forget about that for a second, and just consider your question, here is what happened.
     
    What you wanted (echo a string 10x)
     

    $myVar = "This is awesome"; for ($i = 0; $i < 10; $i++){ echo $myVar . '<br>'; } What you did: 

    $myVar = "This is awesome"; for ($i = 0; $i < 10; $i++){ echo $myVar[$i] . '<br>'; } What is happening then? In this second case, what you are asking php to do, is to try and transform $myVar into an array from a string.PHP is happy to do this for you, as it already considers a string to be an array of characters.
     
    So what your code does is echo a single character from the $myVar string each time, and since $i is being incremented you get this:
     
    $myVar[0] .. then $myVar[1] .. then $myVar[2] etc. until the loop condition becomes false. In your example, it will loop 10 times, or up to 10 letters of the string: from $myVar[0] - $myVar[9].
     
    The loop itself is going to repeat the individual instructions contained within the control structure -- { ... } until the condition becomes false. With "for loops", you just have some place holders for built in variables that it will initialize, and increment or decrement each time the loop is entered.
     
    In other words, the $i is something that you may or may not want to be using inside the loop, but it's not required. Just to echo 10 strings, there is no need for you to reference $i inside the loop at all.
  6. gizmola's post in Creating a prepared statement from an array was marked as the answer   
    PDO::PARAM_STR is a constant defined with an integer value.
     
    There is absolutely no reason that you should have an issue assigning the value to an array element and using it later. It's an integer value when it's passed.
     
    We would have to see the code that does this "cramming" to understand whether your technique is valid or doing something different than what you think it is.
     
    With that said:
     

    $foo['type'] = PDO::PARAM_STR; Is entirely different from: 

    $foo['type'] == 'PDO::PARAM' . '_STR'; We need to know the specifics of what you were trying to do there that lead you down this path in the first place.
  7. gizmola's post in 4 bytes to float was marked as the answer   
    Here's a more modern, simpler and cleaner way of approaching this, that incorporates the advice already provided
     

    <?php $file = new SplFileObject("myfile.dat"); $raw = ''; while (!$file->eof()) { // Get one line from the file. $values = explode(',', $file->fgets()); $raw .= chr($values[1]); // Is this the 4th value? if (0 == $values % 4) { // Do whatever you need with the value. Just echoed it here echo unpack('f', $raw); $raw = ''; } } // Unset the file to close the file handle. $file = null;
  8. gizmola's post in Undefined Index if ID added to text field was marked as the answer   
    An undefined index occurs when you try and reference a key in an array that doesn't exist. Based on the info you provide that was the attempted referencing of "$_POST['company_address']". Clearly, prior to the api actually returning something, that variable didn't exist in the POST data.
     
    You can improve your error checking by using functions like array_key_exists or trying:
     

    if (isset($POST['some_key'])) { } else { // Deal with error, it's not going to work }
  9. gizmola's post in ANALYZE/ OPTIMISE in MYSQL was marked as the answer   
    The answer really depends on the engine, but the basic idea is that analyze looks at key distribution in the table and updates some statistics in the data dictionary so that the query optimizer can make informed decisions in regards to when it should use an index or ignore it.
     
    Optimize is basically analyze+ some table restructuring, but this again is highly dependent on the storage engine.  Innodb doesn't typically need analyze, as it has statistical updates baked in.  By the same token the way data is stored in innodb vs myisam is completely different, so there's literally nothing common between engines, and that certainly is true of the other engines that have come along in Maria etc.
  10. gizmola's post in same table delete and insert was marked as the answer   
    Yes you can enclose whatever you want in a transaction.  That is the point of them -- and they are of course not limited to one table.  You could insert in table A, Delete from Table B, and update table C, all inside one transaction.
     
    The important thing to know is that with mysql your tables need to be of an engine type that supports transactions.  Most people have traditionally used Innodb engine tables for this requirement.
×
×
  • 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.