PHP Error in argument option not found r - php

I have a script that I'm using to run cron jobs for WP All Import Pro. The script ran with no errors on Debian Jessie, I am in the process of moving to a dedicated server running CENTOS 6.7 x86_64, WHM 11.50.0 & cPanel.
Running the script on the new server throws this error & fills up the custom log file:
Error in argument 2, char 2: option not found r
The -r option is for running php without script tags:
-r <code> Run PHP <code> without using script tags <?..?>
Not sure what to do at this point, any help would be greatly appreciated.
PHP CLI Version
root#host [~]# php-cli -v
PHP 5.5.28 (cli) (built: Aug 28 2015 14:51:30)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with the ionCube PHP Loader v4.7.5, Copyright (c) 2002-2014, by ionCube Ltd., and
with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
with Suhosin v0.9.36, Copyright (c) 2007-2014, by SektionEins GmbH
THE SCRIPT
#!/bin/bash
#!/usr/bin/php-cli
## http://devlog.rolandow.com/2014/11/wp-import-cron-cli-update/
while getopts ":j:" opt; do
case $opt in
j)
jobId=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
if [ "$jobId" = "" ]; then
echo No job id
exit 1
fi
# Set magic variables for current FILE & DIR
__FILE__="$(test -L "$0" && readlink "$0" || echo "$0")"
__DIR__="$(cd "$(dirname "${__FILE__}")"; echo $(pwd);)"
LOGFILE="${__DIR__}/tmp/wpai_cron_${jobId}.log"
CURLOG="${__DIR__}/tmp/wpai_cron_${jobId}_current.log"
DONE=0
function log {
echo "$(date): $*" >>$LOGFILE
}
log "Start import for jobID $jobId"
cd $__DIR__/public_html
php -e -r 'parse_str("import_key=ica&import_id='$jobId'&action=trigger", $_GET); include "wp-cron.php";' >>$LOGFILE 2>&1
sleep 1
while [ $DONE -eq 0 ]
do
php -e -r 'parse_str("import_key=ica&import_id='$jobId'&action=processing", $_GET); include "wp-cron.php";' >$CURLOG 2>&1
cat $CURLOG >>$LOGFILE
DONE=$(grep 'is not triggered' $CURLOG | wc -l)
sleep 1
done
rm $CURLOG
log "End of import for jobId $jobId"
log ""
log ""
THE ERROR
Fri Sep 4 05:17:41 EDT 2015: Start import for jobID 04
Error in argument 2, char 2: option not found r
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
php <file> [args...]
-a Run interactively
-b <address:port>|<port> Bind Path for external FASTCGI Server mode
-C Do not chdir to the script's directory
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse <file>. Implies `-q'
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-q Quiet-mode. Suppress HTTP Header output.
-s Display colour syntax highlighted source.
-v Version number
-w Display source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
-T <count> Measure execution time of script repeated <count> times.

I have exactly the same script and set up as you, changing
php -e -r
to
php5-cli -e -r
made it run smoothly. Note it's in 2 places in the script.

Related

Add php and composer alias on QNAP Startup

I came across a couple of issues with my QNAP NAS TS-251+ whilst developing a new project these are:
1) There is no php alias and when I add one via command line it is removed on NAS Restart.
2) A similar thing happens for Composer except on restart it removes Composer as well from the system.
How can I stop this from happening or get around it so that when my NAS restarts the php and composer alias are already set.
I managed to resolve this issue by adding a new script that runs when my NAS starts up. QNAP have provided some basic instructions on how to add a startup script on their wiki page under Running Your Own Application at Startup. However I added a couple more steps t
These steps are fairly basic:
Login to your NAS Server via SSH.
Run the following command mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config (Running ls /tmp/config will give you something similar to below)
Run vi /tmp/config/autorun.sh this will allow you to edit/create a file called autorun.sh **
For me I wanted to keep this file as simple as possible so I didn't have to change it much, so the script is just called from with this Shell Script. So add the following to autorun.sh.
autorun.sh code example:
#!/bin/sh
# autorun script for Turbo NAS
/share/CACHEDEV1_DATA/.qpkg/autorun/autorun_startup.sh start
exit 0
You will notice a path of /share/CACHEDEV1_DATA/.qpkg/autorun/ this is where my new script that I want to run is contained, you don't have to have yours here if you don't want to however I know the script will not be removed if placed here. autorun_startup.sh this is the name of the script I want to be running, and start is the command in the script I want to be running.
Run chmod +x /tmp/config/autorun.sh to make sure that autorun.sh is actually runnable.
Save the file and run umount /tmp/config (Important).
Navigate to the folder you have put in the autorun.sh (script in my case /share/CACHEDEV1_DATA/.qpkg/autorun/) and create any folders along the way that you need.
Create your new shell file using vi and call it whatever you want (Again in my case it is called autorun_startup.sh) and add your script to the file. The script I added is below but you can add whatever you want to you startup script.
autorun_startup.sh code example:
#!/bin/sh
RETVAL=0
QPKG_NAME="autorun"
APACHE_ROOT=`/sbin/getcfg SHARE_DEF defWeb -d Qweb -f
/etc/config/def_share.info`
QPKG_DIR=$(/sbin/getcfg $QPKG_NAME Install_Path -f /etc/config/qpkg.conf)
addPHPAlias() {
/bin/cat /etc/profile | /bin/grep "php" | /bin/grep "/usr/local/apache/bin/php" 1>>/dev/null 2>>/dev/null
[ $? -ne 0 ] && /bin/echo "alias php='/usr/local/apache/bin/php'" >> /etc/profile
}
addComposerAlias() {
/bin/cat /etc/profile | /bin/grep "composer" | /bin/grep "/usr/local/bin/composer" 1>>/dev/null 2>>/dev/null
[ $? -ne 0 ] && /bin/echo "alias composer='/usr/local/bin/composer'" >> /etc/profile
}
addPHPComposerAlias() {
/bin/cat /etc/profile | /bin/grep "php-composer" | /bin/grep "/usr/local/apache/bin/php /usr/local/bin/composer" 1>>/dev/null 2>>/dev/null
[ $? -ne 0 ] && /bin/echo "alias php-composer='php /usr/local/bin/composer'" >> /etc/profile
}
download_composer() {
curl -sS https://getcomposer.org/installer | /usr/local/apache/bin/php -- --install-dir=/usr/local/bin --filename=composer
}
case "$1" in
start)
/bin/echo "Enable PHP alias..."
/sbin/log_tool -t 0 -a "Enable PHP alias..."
addPHPAlias
/bin/echo "Downloading Composer..."
/sbin/log_tool -t 0 -a "Downloading Composer..."
download_composer
/bin/echo "Enable composer alias..."
/sbin/log_tool -t 0 -a "Enable composer alias..."
addComposerAlias
/bin/echo "Adding php composer alias..."
/sbin/log_tool -t 0 -a "Adding php composer alias..."
addPHPComposerAlias
/bin/echo "Use it: php-composer"
/sbin/log_tool -t 0 -a "Use it: php-composer"
;;
stop)
;;
restart)
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL
Run chmod +x /share/CACHEDEV1_DATA/.qpkg/autorun/autorun_startup.sh to make sure your script is runnable.
Restart your NAS System to make sure the script has been run. After restart for my script I just did php -version via terminal to make sure that the php alias worked and it did.
(*) With steps 3 and 8 you can either do this via something like WinSCP or continue doing it via command line (SSH). For me I chose to do it via WinSCP but here is the command still for SSH
I am fairly new to server related stuff so if anyone has a better way cool.

Laravel Artisan PHP version error in 1and1 server

I have a server hosted on 1and1 and I am using Laravel. When I want to execute the Artisan command to schedule a tasks, I get this error:
$ php artisan schedule:run
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /htdocs/artisan on line 31
Parse error: syntax error, unexpected T_STRING in /htdocs/artisan on line 31
After a lot searches, nothing solved my issue (do an alias for PHP, call $ php5.5 instead $ php, etc.).
The main problem is that a call to php uses version 4.4.9 of PHP, instead 5.5 that Laravel needs.
$ php -v
PHP 4.4.9 (cgi-fcgi) (built: Mar 31 2016 16:41:29)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
$ php5.5 -v
PHP 5.5.35 (cgi-fcgi) (built: May 3 2016 07:09:03)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
I changed the call to php5.5 and altered the Artisan file, calling this on the first line:
#!/usr/local/bin/php5.5
<?php
But at the end I always get this from artisan module calls:
Running scheduled command: '/usr/local/bin/php' 'artisan' moneySaved:send >> './logs/log.log' 2>&1 &
So the problem must come from who generates those "Running scheduled command" lines.
After a research, the problem was in the way that Symfony internal scripts "locate" the php path to call it. Specifically those:
epoc/vendor/symfony/process/PhpExecutableFinder.php
epoc/vendor/laravel/framework/src/Illuminate/Console/Scheduling/Schedule.php
The binary var holds the path to call PHP. In my case I forced it to use the 1and1 path for php5.5, and that's all.
public function command($command, array $parameters = []) {
//$binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
$binary = "/usr/local/bin/php5.5";​
if (defined('HHVM_VERSION')) {
$binary .= ' --php';
}​
if (defined('ARTISAN_BINARY')) {
$artisan = ProcessUtils::escapeArgument(ARTISAN_BINARY);
} else {
$artisan = 'artisan';
}​
return $this->exec("{$binary} {$artisan} {$command}", $parameters);
}
Now it works!
The problem is that when running scheduled commands, Laravel uses Symfony's "PhpExecutableFinder" to identify and locate the path to the PHP binary to use to run the scheduled commands.
And depending on the context from which artisan schedule:run is called, PhpExecutableFinder will not return the path to the correct PHP binary.
However, in the current version of PhpExecutableFinder there is an if clause which checks whether PHP_PATH is defined in the environment. If so and set to an executable path, it is returned.
So I added export PHP_PATH=/usr/local/bin/php8.0; right before the call to artisan schedule:run in the crontab:
* * * * * export PHP_PATH=/usr/bin/php8.0; $PHP_PATH artisan schedule:run >> /dev/null 2>&1
and instead of the default (and wrong) /usr/bin/php, the correct
/usr/bin/php8.0 was used to run the scheduled commands.
This fixed the problem I had with running FreeScout on IONOS hosted webspace (see also this FreeScout issue).

How to get iOS to run a sub process?

I am writing an app for iOS that will start the php binary as a sub process.
The following code is used:
NSString * command = #"/bin/sh -c '";
command = [command stringByAppendingString:[BibleditPaths php]];
command = [command stringByAppendingString:#" -v' > /tmp/php.txt 2>&1"];
int output = system ([command UTF8String]);
NSString* msg = [#(output) stringValue];
NSLog(msg, #"");
The php binary can be started on a jailbroken iPad from the command line. This is the output:
PHP 5.4.31 (cli) (built: Aug 19 2014 11:06:21)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
When starting the php binary from the code above, iOS sends the SIGKILL signal.
The php binary does not run or produce any output.
/bin/sh produces this output:
sh: line 1: 2806 Killed: 9 /bin/sh -c '/var/mobile/Applications/DFE552CC-ECBE-4A73-82CF-24870E5D9F62/Library/usr/local/bin/php -v' > /tmp/php.txt 2>&1
2014-09-15 17:33:41.676 PHPRunner[2804:60b] 35072
What can I do to get iOS to run this process successfully?
This question was posted on the Apple iOS development forum (https://devforums.apple.com/index.jspa).
The response there was:
"None of that is supported (or permitted by the application sandbox) on iOS."
Subsequently the question was deleted from the forum.
I am posting the answer here so the information is kept for the public.

Windows CMD.exe "The system cannot find the path specified."

Solved by restoring Windows to previous state
The message (The system cannot find the path specified.) shows...
1) When i open new CMD (Win+R => cmd). It starts with introduction. (on line 3)
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
The system cannot find the path specified.
C:\Users\ViliamKopecky>
2) When i execute some command like cmd /C dir (or cmd /C php -v or whatever) (on line 2)
C:\Users\ViliamKopecky>cmd /C dir
The system cannot find the path specified.
Volume in drive C is Windows7_OS
Volume Serial Number is 8230-1246
...
C:\Windows\System32>cmd /C php -v
The system cannot find the path specified.
PHP 5.4.8 (cli) (built: Oct 16 2012 22:30:23)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
3) (the most annoying) when i run exec function from PHP or Node.js or probably any scripting lang. (which are probably runned from inside as cmd /C <command>)
The message does not show...
1) when i execute the command right from the cmd (or mingw, ...)
C:\Users\ViliamKopecky>dir
Volume in drive C is Windows7_OS
Volume Serial Number is 8230-1246
Directory of C:\Users\ViliamKopecky
Let's start with simple command from cmd.
php -r "exec('dir', $stdout, $stderr); print(implode(\"\n\", $stdout), $stderr);"
and the result is like this (the directory test is empty - that is correct):
E:\test>php -r "exec('dir', $stdout, $stderr); print(implode(\"\n\", $stdout), $stderr);"
The system cannot find the path specified.
Volume in drive E is www
Volume Serial Number is 0C99-95EC
Directory of E:\test
09.11.2012 22:42 <DIR> .
09.11.2012 22:42 <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 13 495 296 000 bytes free
int(1)
Which shows that the command dir has is executed from php correctly. Only thing thats wrong is the second line - The system cannot find the path specified. - that should not be there.
This message is output by exec from PHP (and also from Node.js as require('child_process').exec("dir", function(err, stdout, stderr) {console.log(stderr)});)
When I execute command right from cmd (or mingw, etc.) it executes correctly without the message. Environment variable PATH seem ok. Problem is just executing from script environment through exec functions.
How to get rid of that annoying message? Thanks
The problem is that some program has been set to autorun when you run cmd.exe.
In my case it was ANSICON that was installed... and then I moved the file without properly uninstalling.
I found a solution in this blog post:
http://carol-nichols.com/2011/03/17/the-system-cannot-find-the-path-specified/
The short version is to find
HKCU\Software\Microsoft\Command Processor\AutoRun
and clear the value.
This message can mean a path in the PATH enviromental variable doesn't exist.
The following PowerShell command will print missing paths.
($env:path).Trim(";").Split(";") | ? {-not (test-path $_)}
e.g.
> ($env:path).Trim(";").Split(";") | ? {-not (test-path $_)}
C:\Program Files\CMake\bin
C:\Program Files\SDCC\bin
C:\Users\wjbr\AppData\Local\Programs\Microsoft VS Code\bin
References
http://carol-nichols.com/2011/03/17/the-system-cannot-find-the-path-specified/
https://javarevisited.blogspot.com/2017/01/the-system-cannot-find-path-specified-error-in-command-prompt.html
This actually looks like a startup error with PHP, not with your code. Does
php -r "echo 1;"
also throw the same error? If so, your php.ini file or an include may be pathed incorrectly.
php -i
should give you more info.
I think you should try this out ! I had the same issue and solved it like this :
ok type : cd\windows\system32
After that you will see this: System32/:
Type what you want (ex:ipconfig):
System32: ipconfig
Then that should do it !
:)

Can't run bash script in PHP

I'm trying to run bash script in PHP but can't run it.
php -v
PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:58)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
Ubuntu 12.04 LTS 64 bit.
My php code:
$cmd='/www/var/pl/bash.sh';
$retval =-1;
exec( $cmd, $output ); //executing the exec function.
foreach( $output as $tmp )
{
echo "$tmp <br>";
};
bash.sh:
#!/bin/bash
swipl --quiet -s /var/www/pl/ples.pl -g "f(R, gel), writeln(R),open('/var/www/pl/in.txt',write, Stream),
write(Stream, (R)),
nl(Stream),
close(Stream)" -t halt.
What am I doing wrong?
And I can run bash.sh in the Linux terminal.
When you run the script in the terminal you are executing it under the account you are logged in to. You have a shell setup with a search path etc.
When php executes the script, it has not a shell setup, and runs under the webserver user account. When executing:
make sure you have complete paths to your file, swipl is not enough, it should be /path/to/swipl
make sure the webserver process has enough access rights to get everything it needs.
Most likely it is either a path or permission problem; for example the user the web application runs as, has no idea where the swipl program is.
Add 2>&1 to the command line before exec'ing it, so that it tells you what the problem is. Or you can find the stderr output into the web server error log (or PHP error log; check its path and settings in php.ini).

Categories