I do not understand very well what a PHP process is - php

I want to lock a file by flock. I read the documentation and it says that
These locks only apply to the current PHP process.
So what is a PHP process ? If there is a PHP project inside a web server , and there are many clients opening the project on their computer's browser , are all these clients computers starting different PHP processes ? If so , does flock then really lock in that situation ? What I want is to lock a file on a webserver if I am the first accessing the file , even if there are many other clients computers trying to launch the same functionality on a page !

This all depends on which os and how you have your server and php setup through the web server. On windows, I believe its one php.exe process which shouldn't be too difficult to grasp. On linux, one php process handles each apache request.
For example, I issued >
ps aux | grep php
I got:
root 4346 0.0 1.6 345920 19068 pts/0 T Mar12 0:04 emacs mission_insert.php
this show that I opend a php file called mission_insert.php with emacs, which doesn't show anything about a php request but its handled through httpd/apache.
When I issue >
ps aux | grep httpd
I get the following:
root 3255 0.0 2.3 616964 27720 ? Ss Mar11 0:22 /usr/sbin/httpd -DFOREGROUND
apache 7227 0.0 1.8 723060 22040 ? S 03:35 0:01 /usr/sbin/httpd -DFOREGROUND
apache 7228 0.0 1.7 722828 20752 ? S 03:35 0:01 /usr/sbin/httpd -DFOREGROUND
apache 7229 0.0 1.7 723500 20136 ? S 03:35 0:00 /usr/sbin/httpd -DFOREGROUND
apache 7230 0.0 1.8 723008 22324 ? S 03:35 0:01 /usr/sbin/httpd -DFOREGROUND
apache 7374 0.0 1.7 723136 20868 ? S 09:38 0:01 /usr/sbin/httpd -DFOREGROUND
apache 7380 0.0 2.0 725124 23840 ? S 09:38 0:01 /usr/sbin/httpd -DFOREGROUND
apache 7381 0.0 1.8 725140 21392 ? S 09:38 0:01 /usr/sbin/httpd -DFOREGROUND
apache 7382 0.0 1.9 724620 22880 ? S 09:38 0:00 /usr/sbin/httpd -DFOREGROUND
apache 7385 0.0 1.7 723028 20864 ? S 09:38 0:01 /usr/sbin/httpd -DFOREGROUND
apache 7578 0.0 0.9 617232 11396 ? S 10:22 0:00 /usr/sbin/httpd -DFOREGROUND
root 7628 0.0 0.0 112640 960 pts/0 R+ 11:27 0:00 grep --color=auto httpd

Related

codeigniter error with call to undefined function codeigniter\locale_set_default() search

This is the error I see in CodeIgnitor 4 on a new server installation.
Fatal error: Uncaught Error: Call to undefined function CodeIgniter\locale_set_default()
When I look at potential problems I see that I have the intl extension installed but when I do this command:
php -i | grep -i intl
returns
intl.default_locale => no value => no value
In addition to adding an actual locale like this in php.ini file:
intl.default_locale="en-US"
ensure that this extension is enabled... in other words remove the ; in this line...
extension=php_intl.dll
and after a restart this fixed for me.
So the solution I've found is to edit the PHP configuration files and add:
intl.default_locale="en-US"
I added it to /etc/php.d/20-intl.ini but your local configuration may vary.
Then I tested the apache configuration and restarted:
apachectl configtest
apachectl restart
The error didn't go away so I continued my search and found php-fpm was running:
ps auxwww | grep -i PHP
which returned
apache 10499 0.0 0.4 292148 16672 ? S 17:07 0:00 php-fpm: pool www
apache 10502 0.0 0.4 292148 16696 ? S 17:07 0:00 php-fpm: pool www
apache 10503 0.0 0.3 290076 13756 ? S 17:07 0:00 php-fpm: pool www
apache 10504 0.0 0.3 290076 13768 ? S 17:07 0:00 php-fpm: pool www
apache 10506 0.0 0.2 288028 11624 ? S 17:07 0:00 php-fpm: pool www
apache 20201 0.0 0.3 290076 13744 ? S 17:16 0:00 php-fpm: pool www
so I restarted that service with this command:
service php-fpm restart
and now everything seems to be running perfectly. There were still a few permissions issues to address with a new install of CodeIgnitor but those are for another post.

How to run php-fpm master process as non root user?

How do i run php-fpm master process as non root user
root 10275 0.0 0.5 192856 23104 ? Ss Nov20 0:01 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)

Caddy Server, http.fastcgi 502 Error

My Caddy File
http://bot.vibs.tech {
root /home/caddy/www/botsite
tls off
errors {
404 /home/caddy/www/botsite/404.html
}
fastcgi / 127.0.0.1:9001 php {
ext .php
split .php
index index.php
}
}
The Webpage http://bot.vibs.tech/test.php
Home Page http://bot.vibs.tech
My PHP Script
<?php
if($_POST["submit"]) {
$test=$_POST["botsname"];
$redis->set(';message';, $test;);
$value = $redis->get('message');
<p>$value</p>
}
if (empty($url)) {
echo "<h2><div style=\"color: Black;\">THANK YOU, YOUR BOT IS BEING MADE!</div></h2>";
echo "<h2><div style=\color: Black;\"><a href=http://bot.vibs.tech/>HOME</a></div></h2>";
}
Tried lots of different things, not sure what else i could try to do.
Also im trying to implement Redis to this so i can have a database from a form im currently working on.
Additional Info
tried /etc/init.d/php7.0-fpm status
● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor
preset: enabled)
Active: active (running) since Sat 2017-08-26 11:27:49 EDT; 4min 55s ago
Process: 17295 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)
Main PID: 17304 (php-fpm7.0)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
CGroup: /system.slice/php7.0-fpm.service
├─17304 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
├─17305 php-fpm: pool www
└─17306 php-fpm: pool www
Aug 26 11:27:49 Vibs systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...
Aug 26 11:27:49 Vibs systemd[1]: Started The PHP 7.0 FastCGI Process Manager.
Hint: Some lines were ellipsized, use -l to show in full.
Says its started.
Also Did, ps aux | grep php-fpm
root 17304 0.0 0.8 211748 17128 ? Ss 11:27 0:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data 17305 0.0 0.1 211748 3224 ? S 11:27 0:00 php-fpm: pool www
www-data 17306 0.0 0.1 211748 3224 ? S 11:27 0:00 php-fpm: pool www
caddy 18003 0.0 0.0 11228 884 pts/0 S+ 15:33 0:00 grep --color=auto php-fpm

Laravel queue:listen takes up all the server memory all the time

I am using Amazon Beanstalk to host my Laravel Application. I created a special configuration so that my queue:listen will auto re-start on deployment with supervisor.
[unix_http_server]
file=/tmp/supervisor.sock
chmod=0777
[supervisord]
logfile=/var/app/support/logs/supervisord.log
logfile_maxbytes=25MB
logfile_backups=2
loglevel=warn
pidfile=/var/run/supervisord/supervisord.pid
nodaemon=false
nocleanup=true
user=webapp
[program:laravel_queue]
command=php artisan queue:listen --queue=email,activity,purging,misca --memory=256 --env=production
directory=/var/app/current
stdout_logfile=/var/app/support/logs/laravel-queue.log
logfile_maxbytes=25MB
logfile_backups=2
redirect_stderr=true
autostart=true
autorestart=true
startretries=86400
This works great and my problem is after a day or too my server memory always reaches 95%!
I inspected the memory and noticed a bunch of http processes that were started by queue:listen but for some reason never killed (note all jobs succeeded, no failure).
webapp 22923 0.0 0.4 673948 19032 ? S 18:10 0:00 /usr/sbin/httpd -D FOREGROUND
webapp 22926 0.0 0.8 674588 35512 ? S 18:10 0:00 /usr/sbin/httpd -D FOREGROUND
webapp 22929 0.0 0.4 673948 19032 ? S 18:11 0:00 /usr/sbin/httpd -D FOREGROUND
webapp 22931 0.0 0.9 674932 37576 ? S 18:11 0:00 /usr/sbin/httpd -D FOREGROUND
webapp 22932 0.0 0.4 673948 19032 ? S 18:11 0:00 /usr/sbin/httpd -D FOREGROUND
webapp 22934 0.0 0.8 674600 35536 ? S 18:11 0:00 /usr/sbin/httpd -D FOREGROUND
webapp 22935 0.0 0.8 674588 35512 ? S 18:11 0:00 /usr/sbin/httpd -D FOREGROUND
Why are these http processes which I assume are queue:workers not terminating?
While i am having the same issue, there is an atttribute for the program config for supervisor that you are missing
Try adding numprocs and then how many individual process you would like to run
Reference Laravel's Example Supervisor Config in the Documentation

My nginx + php-fm webserver is able to serve web pages that have permission 000. Why?

Perhaps i'm missing something extremely basic, but how is it that my web server is able execute and serve content from php files that have permission 000?
Here's the file in question: http://178.62.125.162/test.php
Location is:
/usr/share/nginx/html/wordpress/test.php
Here's the ls:
---------- 1 deploy deploy 21 May 22 09:40 test.php
nginx.conf has line:
user www-data;
So it's not running as root or anything.
ps aux | grep [n]ginx
root 30223 0.0 0.1 85876 1364 ? Ss May21 0:00 nginx: master process /usr/sbin/nginx
www-data 30224 0.0 0.1 86172 1796 ? S May21 0:03 nginx: worker process
www-data 30225 0.0 0.1 86172 1796 ? S May21 0:03 nginx: worker process
www-data 30226 0.0 0.2 86516 2732 ? S May21 0:00 nginx: worker process
www-data 30227 0.0 0.1 86172 1796 ? S May21 0:03 nginx: worker process
Looks normal to me, AFAIK the master process running as root is expected.
And php-fm:
ps aux | grep php
root 30311 0.0 1.8 309068 18580 ? Ss May21 0:02 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 30314 0.0 3.5 393324 36176 ? S May21 0:01 php-fpm: pool www
www-data 30315 0.0 3.1 388956 32112 ? S May21 0:01 php-fpm: pool www
www-data 30391 0.0 2.9 389828 29528 ? S May21 0:00 php-fpm: pool www
I can't even open the file myself, logged in as deploy:
cat test.php
cat: test.php: Permission denied
php test.php
Could not open input file: test.php
Googled everywhere, but most things I find are related to the opposite- people getting Forbidden errors.
Perhaps it's because it's in /usr/share? Thanks!
Extra info:
Ubuntu x64 LTS
PHP-FM
Update:
Restarting the php-fm service after changing the permission fixes it. But this makes no sense to me:
chmod 000 test.php - web echos "test"
service php5-fm restart - Access Denied
chmod 644 test.php - web echos "test". No need for a restart this time?
chmod 000 test.php - web echos "test".
Thanks to Alexander Ushakov for providing the answers.
The file with the readable permission had been cached by php-fm. Restarting php-fm meant that the cache was cleared and the web server then served the new file with the restricted access.

Categories