Cannot kill a process by a PHP Script running behind nohup

I have a php script that perform some actions after killing some old processes.

act.php

$pids = shell_exec('ps aux | grep "saso" | awk '{print $2}'');
$pids = str_replace("n", ' ', $pids);
$pids = array_filter(explode(' ', $pids));

foreach ($pids as $pid) {
    shell_exec('kill -9 ' . $pid . ' > /dev/null 2>&1 &');
}

// reset of the code . ..

The script works well by running php act.php. It fetch process ids, kill it, then run the reset.

But it is not working when I run nohup php act.php & or nohup php act.php. The process is not killed.

I need nohup to run the script in the background with no hang up.

Can’t PHP script fetch pids behind nohup ? and are there any alternatives ?

Thanks in advance.

Symfony5: form for self-referencing many-to-many

In a Symfony5 application, how can we utilize the form-component to correctly set up a self-referencing, many-to-many relationship?

Note: this is purely about the form-side of things, Doctrine is already happy.

Let’s say we have a “Person”-entity, and these Person-instances host guests, who are also Persons:

#[Entity(repositoryClass: PersonRepository::class)]
class Person
{
    #[Id]
    #[GeneratedValue]
    #[Column(type: Types::INTEGER)]
    private int $id;

    #[Column(type: Types::STRING, length: 255)]
    private string $firstName;

    #[Column(type: Types::STRING, length: 255)]
    private string $lastName;

    /** @var Collection<Person> */
    #[ManyToMany(targetEntity: self::class, inversedBy: 'guestsHosted')]
    private Collection $hosts;

    /** @var Collection<Person> */
    #[ManyToMany(targetEntity: self::class, mappedBy: 'hosts')]
    private Collection $guestsHosted;

    public function __construct()
    {
        $this->fellowshipHosts = new ArrayCollection();
        $this->fellowsHosted = new ArrayCollection();
    }

    // getters/setters ommitted for brevity


    public function addHost(self $host): self
    {
    }

    public function removeHost(self $host): self
    {
    }

    public function addGuestsHosted(self $guestHosted): self
    {
    }

    public function removeGuestsHosted(self $guestsHosted): self
    {
    }

What I would like to achieve is a form with a collection of addable/removable rows, where the user then is able to add a row, select an existing other person as their host, add another row, select another person, and so on. A simple mockup:

How do I achieve this using Symfony’s form-component? What I have in there now does not work due to recursion on the same form-type:

class PersonType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder           
            ->add('firstName', null, [])
            ->add('lastName', null, [])            
            ->add('hosts', CollectionType::class, [
                'entry_type' => self::class,
                'entry_options' => ['label' => false],
                'required' => false,
                'allow_delete' => true,
                'allow_add' => true,
                'by_reference' => false,
            ]);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Person::class,
        ]);
    }
}

NB: I’ve built similar UIs like this in the past and know about the little dance involving form.vars.prototype and hooking up the JS to that. Where I’m lost is how to map this association on the form-level, so that I get a dropdown of all Persons, and map that into the $hosts property of the entity.

Any help is appreciated!

Why are my Symfony Router are not Working?

I am currently creating a Symfony Project for School and i was just trying some things out with this Security Bundle… I was creating the Registration Controller with this php bin/console make:registration-form Command and it worked out fine. The Files got created and i got no Errors but when i am trying to go to /register they just show me my index.php all the time… if i delete index.php its always # Page not Found from my Symfony Local Server… Im just testing out so im just using this localhost Webserver from Symfony. I tested out the Route with php bin/console router:match /register and it showed green, it works and exists. But when i try going to the Site nothing happens.

namespace AppController;

use AppEntityUser;
use AppFormRegistrationFormType;
use AppRepositoryUserRepository;
use AppSecurityEmailVerifier;
use DoctrineORMEntityManagerInterface;
use SymfonyBridgeTwigMimeTemplatedEmail;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentMimeAddress;
use SymfonyComponentPasswordHasherHasherUserPasswordHasherInterface;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyCastsBundleVerifyEmailExceptionVerifyEmailExceptionInterface;

class RegistrationController extends AbstractController
{
    private EmailVerifier $emailVerifier;

    public function __construct(EmailVerifier $emailVerifier)
    {
        $this->emailVerifier = $emailVerifier;
    }

    #[Route('/register', name: 'app_register')]
    public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response
    {
        $user = new User();
        $form = $this->createForm(RegistrationFormType::class, $user);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            // encode the plain password
            $user->setPassword(
            $userPasswordHasher->hashPassword(
                    $user,
                    $form->get('plainPassword')->getData()
                )
            );

            $entityManager->persist($user);
            $entityManager->flush();

            // generate a signed url and email it to the user
            $this->emailVerifier->sendEmailConfirmation('app_verify_email', $user,
                (new TemplatedEmail())
                    ->from(new Address('[email protected]', 'Julian Schaefers'))
                    ->to($user->getUserIdentifier())
                    ->subject('Please Confirm your Email')
                    ->htmlTemplate('registration/confirmation_email.html.twig')
            );
            // do anything else you need here, like send an email

            return $this->redirectToRoute('_profiler_home');
        }

        return $this->render('registration/register.html.twig', [
            'registrationForm' => $form->createView(),
        ]);
    }

    #[Route('/verify/email', name: 'app_verify_email')]
    public function verifyUserEmail(Request $request, UserRepository $userRepository): Response
    {
        $id = $request->get('id');

        if (null === $id) {
            return $this->redirectToRoute('app_register');
        }

        $user = $userRepository->find($id);

        if (null === $user) {
            return $this->redirectToRoute('app_register');
        }

        // validate email confirmation link, sets User::isVerified=true and persists
        try {
            $this->emailVerifier->handleEmailConfirmation($request, $user);
        } catch (VerifyEmailExceptionInterface $exception) {
            $this->addFlash('verify_email_error', $exception->getReason());

            return $this->redirectToRoute('app_register');
        }

        // @TODO Change the redirect on success and handle or remove the flash message in your templates
        $this->addFlash('success', 'Your email address has been verified.');

        return $this->redirectToRoute('app_register');
    }
}

SQL Database Entry and Query [duplicate]

Hello experts I would be very happy about your help

The aim of the code is that the user can register.
So it should store the values of form id=”signup”

should be stored in the mysql database.

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>Mahlzeit</title>
  <link rel="stylesheet" href="./Login.css">
</head>

<!DOCTYPE html>
<html>
<head>
    <title>Slide Navbar</title>
    <link rel="stylesheet" type="text/css" href="slide navbar Login.css">
<link href="https://fonts.googleapis.com/css2?family=Jost:wght@500&display=swap" rel="stylesheet">
</head>
<body>
    <div class="main">      
        <input type="checkbox" id="chk" aria-hidden="true">
            <div class="signup">
                <form action="http://localhost/Kulinarik/signup_save.php" methode="POST" id="signup">
                    <label for="chk" aria-hidden="true">Sign up</label>
                    <input type="text" name="vorname" placeholder="Vorname" id="vorname">
                    <input type="text" name="nachname" placeholder="Nachname" id="nachname">
                    <input type="email" name="email" placeholder="Email" id="email">
                    <button type="submit" value="signup">Sign up</button>
                </form>
            </div>
            <div class="login">
                <form action="login_save.php" methode="POST" id="login">
                    <label for="chk" aria-hidden="true">Login</label>
                    <input type="email" name="email" placeholder="Email" required=""/>
                    <input type="password" name="pswd" placeholder="Password" required=""/>
                    <button type="submit" value="Login">Login</button>
                    <a class="changepassword">Passwort ändern</a>
                </form>
            </div>
        </input>
    </div>
</body>
</html>

</body>
</html>

and the connection

    <?php
    session_start();
?>
<?php
$con= mysqli_connect('localhost','root','123456', 'userdata',);
$email = $_POST['email'];
$vorname = $_POST['vorname'];
$nachname = $_POST['nachname'];
$passwort = rand(0, 999999);


$result = $con->query("SELECT email FROM signup WHERE email = $email");
if($result->num_rows == 0) {
    $sql = "INSERT INTO signup (vorname, nachname, email, Passwort) vALUES ($vorname, $nachname, $email, $passwort)";
    if ($con->query($sql) === TRUE) {
        header("Location: Login.html");
      } else {
        echo "Error: " . $sql . "<br>" . $con->error;
      }
} else {
    echo "User ist bereits registriert";
}
$mysqli->close();

?>

Do you notice an error ?

The error message says that the array keys are not defined

e.g.:Warning: Undefined array key “email” in C:xampphtdocsKulinariksignup_save.php on line 9

Thanks in advance
Hello experts I would be very happy about your help

Remove duplication and show max count

I have the code below, but my problem is i received PHP Notice: Undefined offset: (from 1 to 7)
error message
and what is very important for me to get country ID only once with the max number.
its counting the number of projects and increase everytime one which is correct and what i need, but need to display it only once
how does it display
the correct result show be similar to:
the correct result

here is my code:-

<table>
    <tr>
        <th>Country ID</th>
        <th>Country Name</th>
        <th>Number of Place</th>
    </tr>

    <?php 
    $country_counts=[];
    $count_country =0;
    $country_count_each=0;
    $ids=array();// Store unique country_id values here
   
    foreach( $projects as $project ) {
        $country_id = $project['Project']['country_id'];
        # Check if the country_id is NOT in the array and display if OK.
        if( isset( $country_counts[ $country_id ] ) || !in_array( $country_id, $ids ) ) {
            $country_counts[$country_id]++;
            $country_count_each = $project['Project']['country_id'];
                if($project['Project']['country_id']==$country_count_each){
                    $count_country+=$country_count_each;
                    $ids[]=$country_id;
                    //echo $country_counts[$country_id];
    ?>
        <tr>
            <td style="width: 30%"><?php echo $project['Project']['country_id']; ?></td>
            <td style="width: 30%"><?php echo 'Country Name'; ?></td>
            <td style="width: 30%"><?php echo $country_counts[$project['Project']['country_id']]; ?></td>
        </tr>
    <?php       
                } 
        }else {
            $country_counts[$country_id] =$country_id;
        }
    }
    $proects_num = count($projects); 

    ?>

</table>

<?php 
    echo '<br>' .'Total projects numbers are: ' . $proects_num .'<br>'; 
    echo $html->link('Home ', $this->webroot.'countries/index/');
?>

the table in database
Table of projects

I need a help in that please

PHPExcel Codeigniter-4 unable to upload more than 50k rows

I want to upload an excel file of 50K columns but it’s unable to read them while I upload 2k row its worked fine and data was uploaded in the database(MySQL) also but when I tried to upload 50K rows at a time its not even showing error also.So my requirement is to upload 50K rows and 40 columns at a time using SpreadsheetReader_XLSX

Not able to fetch data from checkbox

So, i’m working on this real estate project, where users can add room details. Probblem is, when i check the checkbox for room one detail, i get information, but when i check the checkbox for another room (Please watch video), it does not show any information. Why?
Please watch this 20 sec video: link

 <div class=" add-list-tags fl-wrap">
          <!-- Checkboxes -->
                                    <ul class="fl-wrap filter-tags no-list-style ds-tg">
                                        <?php foreach ($action->fetchData("facilities") as $key => $value) {

                                        ?>
                                            <li>
                                                <input type="checkbox" value="<?php echo $value['id']; ?>" name="room_facilities[]">
                                                <label for="<?php echo $value['name']; ?>"> <?php echo $value['name']; ?></label>
                                            </li>
                                        <?php } ?>

                                    </ul>
       <!-- Checkboxes end -->
  </div>

How to make viewforum.php?foo=bar request serve a file instead of a PHP code?

I’m archiving a phpBB forum into flat HTML files, without any PHP code anymore.
I used wget (see How to: Archive a phpBB forum using Wget and preserve styling), and I now have these files:

enter image description here

How to make that Apache will serve example.com/forum/viewforum.php?f=2&start=25 as a file, and not as a request to viewforum.php with a query string? The latter does not work obviously and gives a 404.

I already tried this htaccess with no success:

RemoveHandler .php .phtml .php3
RemoveType .php .phtml .php3
php_flag engine off

Note: this is how I archived the forum:

wget -m -p -np -R "*sid=*,ucp.php*,memberlist.php*,*mode=viewprofile*,*view=print*,viewonline.php*,search.php*,posting.php*" https://forums.example.com

How to display a parent category in a product card

On my site there are product cards with my product. Each product has a category and a subcategory (it functions as Brand> Collection). Using the brands plugin doesn’t work for me.
the display on the product page itself is correct and excellent. (screenshot below). But on the product card, a subcategory is shown that belongs to the product, and I need a parent one. Can someone suggest how to do this?

enter image description here
enter image description here

Wrong image is displayed on browser breakpoints

I wrote a PHP image display function. There is no problem with the function. But I have a problem with breakpoints. On mobile it shows the big picture. I couldn’t understand how to solve the problem.

function imglazy($filen,$altn,$classn) {
    global $imagepath;
    global $cdnsource;
echo '<picture>
<source media="(min-width: 1025px)"
    data-srcset="'.$cdnsource.$imagepath.$filen.'-fl.webp"
    type="image/webp">
<source media="(max-width: 1024px)"
    data-srcset="'.$cdnsource.$imagepath.$filen.'-bg.webp"
    type="image/webp">
<source media="(max-width: 768px)"
    data-srcset="'.$cdnsource.$imagepath.$filen.'-md.webp"
    type="image/webp">
<source media="(max-width: 500px)"
    data-srcset="'.$cdnsource.$imagepath.$filen.'-sm.webp"
    type="image/webp">

<source media="(min-width: 1025px)"
    data-srcset="'.$cdnsource.$imagepath.$filen.'-fl.jpg"
    type="image/jpeg">
<source media="(max-width: 1024px)"
    data-srcset="'.$cdnsource.$imagepath.$filen.'-bg.jpg"
    type="image/jpeg">
<source media="(max-width: 768px)"
    data-srcset="'.$cdnsource.$imagepath.$filen.'-md.jpg"
    type="image/jpeg">
<source media="(max-width: 500px)"
    data-srcset="'.$cdnsource.$imagepath.$filen.'-sm.jpg"
    type="image/jpeg">
<img
    data-srcset="'.$cdnsource.$imagepath.$filen.'-bg.jpg,
        '.$cdnsource.$imagepath.$filen.'-md.jpg,
        '.$cdnsource.$imagepath.$filen.'-sm.jpg"
    data-src="'.$cdnsource.$imagepath.$filen.'-fl.jpg"
    alt="'.$altn.'"
    class="lazyload '.$classn.'">
</picture>';
}

Connect Office 365 use POP3 – PHP

I have a trouble with Office 365 use POP3 method.

Currenty, I can’t connect to this server:

   outlook.office365.com 
   port:995

This is my code example:

<?php
$host = 'outlook.office365.com';
$port = '995';
$username = 'outlook_mail';
$password ='password';
$mbox = imap_open('{'.$host.':'.$port.'/pop3/ssl/novalidate-cert}', $username, $password);

echo "<h1>Mailboxes</h1>n";
$folders = imap_listmailbox($mbox, "{".$host.":".$port ."}", "*");

if ($folders == false) {
    echo "Call failed<br />n";
} else {
    foreach ($folders as $val) {
        echo $val . "<br />n";
    }
}

echo "<h1>Headers in INBOX</h1>n";
$headers = imap_headers($mbox);

if ($headers == false) {
    echo "Call failed<br />n";
} else {
    foreach ($headers as $val) {
        echo $val . "<br />n";
    }
}

imap_close($mbox);

If I change port to 993, it’s OK.
Anyone know this problem? Many thanks!

Yii1 CDbHttpSession not working correctly

I used database session storage approach for using my sessions,

And I used this article too: slow-db-session-table

So I created YiiSession table in my db with this script:

 CREATE TABLE YiiSession
 (
  id CHAR(32) PRIMARY KEY,
  expire INTEGER,
  data BLOB,
  KEY expire_idx (expire) USING BTREE
 );

And my config in config/main.php:

'session' => [
    'class' => 'CDbHttpSession',
    'connectionID' => 'db',
    'sessionTableName' => 'YiiSession',
    'timeout' => 3600 * 24 * 30,
    'autoStart' => false,
    'autoCreateSessionTable' => false
],

I stores all user cart info session values as an object like this:

Yii::app()->session[‘user-cart’] = $this->cartInfo;

Issue

There are some issues,

1- Session, after page redirect sometimes no have any value,there is this problem
with using CDbHttpSession and no in session file working approach.

2- Sometimes session stores but unset session not works, and maybe after calling two
more time the method clears sessions it works.

unset(Yii::app()->session[‘user-cart’]);

What is the problem?
I don’t have any problem with working with session file approach, but db session not working correctly in my codes.

Yii version -> 1.1.23

PHP version -> 7.4