You need a website. You have a website. Why not ceate your own ?
PHP is known as a language to create a Website.
Despite of this, PHP can served as multiporpuse script.
For historical reason. BASH evolve to Perl, Perl Evolve to PHP.
Since we have similar behaviour borrowed form the predecessor,
it would not be so difficult to include PHP in this Tutorial group.
In fact this PHP script version is very similar with Lua script version.
Goal: A script that continuously show date and time,
with Dzen2, and Conky.
Before you dip your toe to scripting,
you might desire to know the reason by reading this overview.
For accounting reason in my company.
I’m still using PHP56 in my notebook.
But for the reader, I moved on to PHP7.
You are free to switch the #shebang.
Do not worry, I do not use any sophisticated code.
Start Simple
Welcome to n00berland. Begin with simple script.
We will use this loop as a source feed to pipe.
This step won’t introduce Pipe nor Fork.
This script only show an infinite loop showing local time.
Each updated in one second interval.
We manage this interval by delaying,
using sleep code.
Beside previous simple loop that is used as Internal Command,
this tutorial also provide Conky as External Command
in asset directory.
I made it as simple as possible.
This step is overview of Pipe between two external command.
Instead of system command, this utilize popen
using two handles: pipein and pipeout.
Next guidance need bidirectional capability.
Bidirectional means, a process can read and write at the same time.
So I append proc_open method.
This is a very simple. Just a few self explanatory lines.
This very short script is using conky
as pipe source feed and less as pipe target.
Showing time and date forever in the console.
This infinite pipe run in time-less fashioned.
I add _ dir _, relative to the PHP source,
to locate the conky script assets.
The same as previous.
But instead of reading from $pipein,
it is managed by internal process using fwrite($pipeout, ...).
Fork Overview
This step use internal function as source feed,
as continuation of previous step.
This step use dzen2, with complete parameters.
This dzen2 is forked, running in the background.
Detached from the script,
no need to wait for dzen2 to finish the script.
This step also add system command that kill
any previous dzen2 instance. So it will be guaranteed,
that the dzen2 shown is coming from the latest script.
Any code after the pcntl_fork()
executed in both parent and child.
The child process has been detached from parent process.
The only different is the $pid.
Polishing The Script
This step, we use conky again, as a source feed.
And also parameterized dzen2 as continuation of previous step.
This step add optional transset transparency,
detached from script. So we two forks, dzen and transset.