php-cli

Same server, same program but started once using one network card and after with another

Hello, I have a Linux server with multiple ips (so, multiple eth0, eth0:0, eth0:1 etc). The script I'm trying to start is a php CLI script which is downloading stuff from an another server API, and I would like to change the IP based on different parameters. Once the script is started, I don't need anymore to change the ip OF THAT SPECIF...

PHP-CLI + File Permissions

When you run a php script in the command line, does is execute with the read/write permissions of the current user or what? ...

How to run a php script in cron

I have found many questions and articles about this but i still have some difficulties. I'm using the following command /usr/bin/php home/domain.com/public_html/cron/script.php I receive the following error Status: 404 Not Found X-Powered-By: PHP/5.2.8 Content-type: text/html No input file specified. i'm using Cpanel, the file is host...

Problems with php-cli and mysql, why is mysql_pconnect() not available?

I've installed various PHP packages to be able to use PHP with Apache but also in the commandline. From both I need to be able to connect to MySQL databases. Pretty simple right? That's what I thought but with php-cli I receive following error: Fatal error: Call to undefined function mysql_pconnect() I have tried starting from scratch...

php long running script

how can I provide feedback for a shell command that may run for quite some time? for example, i need a script that does hg clone ... then in my php i make a call exec('hg clone ...', $output, $return_value); but I wouldn't be able to get the output before the command actually ends. It is stated in the documentation ( http://www.php.n...

popen and file operation

related to this question my script basically runs fine but sometimes it stop responding at the fread function call and I can't seem to find the reason of the failure. private function run_lengthy_job($command, $message) { for($handle = popen($command, 'r'); !feof($handle); sleep(2)) { printf("[%s]\t%s\n", time(), $message);...

PHP clone keyword vs clone() command line CLI issues

Hello, I have been using the clone keyword to duplicate objects like so: $x = clone $obj; as per the manual. This works fine when accessed by browser. phpinfo() reports PHP version 5.2.6. However when run by cron or from the CLI I get "Parse error: syntax error, unexpected T_VARIABLE" from the clone keyword. php -v reports P...

PHP - how to best determine if the current invocation is from CLI or web server?

I need to determine whether the current invocation of PHP is from the command line (CLI) or from the web server (in my case, Apache with mod_php). Any recommended methods? ...

Generic "Killed" error in PHP CRON job

I am working on a CRON job in PHP which has to do a lot of heavy lifting via the database. Think lots and lots of loops. It executes properly when I limit the data set, but when I run it against the full data set, the script errors out with a simple "Killed" message. set_time_limit is (0) and memory_limit is (-1) Here is the code s...

Using the PHP CLI with MAMP

Does MAMP come with the PHP CLI installed? I am trying to run a script from the command line, but using a Mac, with MAMP, and not knowing much about PHP CLI is making it difficult. How should I set up my environment so that I can use the PHP CLI with MAMP? ...

How to use the php command line interactively?

Are there any howtos for using the php command line interactively? I found a lot about running sripts that are in text-files, but not really about the shell with the prompt where I type in commands: $ php -a Interactive shell php > echo "hello world"; hello world php > $a = 1; php > echo $a; 1 php > exit; $ When I go to the linux she...

PHP cli Memory usage optimization

Hello I am trying to code a custom url_rewriter for squid. & also with using some other url_rewriter programs like squidGuard so have to use a wrapper to able use both or any other program. when i try to loop with php. (that's the way how squid communicates with external programs. STDIN/STDOUT. it gives you a url & you have to sen...

Optimizing php command line scripts to process large flat files

I have a large flat file that I need to process in php. I convert the flat file into a normalized database in mysql. There are several million lines in the flat file. I originally tried to use an ORM system while importing the flat file. There was a massive php memory leak problem with that design even with careful freeing of objects. E...

filemtime() not working in Windows PHP-CLI

I just got PHP-CLI working on my Windows machine so I could create scripts using PHP. However, I'm trying to write a script to cleanup my Firefox downloads folder of files older than X number of days, but I can't seem to get the filemtime() function working. Here is the function I wrote: function deleteOldFiles($dir, $days) { $mydir...

php5 cli: no output

Hi, i've got a php script that runs on the command line. To improve it's performance, i would like to completely suppress it's output. How can I do that? Thanks! ...

How to pass file into PHP CLI?

I have a PHP script named "scipt" and a textfile called 'data.txt'. Right now I can execute script, but then I need to type in "data.txt". Is there any way to pass in data.txt as a parameter to "script" so I can run this thing in one line automated? Right now I'm typing: php script {enter} // script runs and waits for me to type filena...

Escaping a literal <?php and <? in a PHP script

I am templatizing my php.ini using PHP. I have a script to set up a development environment by generating httpd.conf, apachectl, and php.ini from templates using a CLI PHP script. Unfortunately there are literal <? and <?php strings in php.ini (in a comment). Is it possible to escape those somehow so php doesn't interpret them as normal ...

PHP Magic Constants

I am trying to get the filename of the script that is running (But not the include it is calling). echo basename(__FILE__); # will always output include.php echo basename($_SERVER['SCRIPT_FILENAME']); # This will do what I want (echo myscript.php), but I was wondering if there was # a better way to grab it, as I have had problems with ...

PHP CLI vs PHP WEB

Hiya All, I am currently running a script that i've created in PHP that parses and sorts out 6 different xml files of around 40mb each. I currently run the script through a browser, and a cron job to wget the page. But sometimes with the server load it can clog up apache and and the rest of the server, Would it make sense to convert...

Suppressing output from exec() calls in PHP

I have a number of command line scripts in PHP that use exec() to perform tasks such as restarting services, loading MySQL timezone files, etc. While exec() itself does not output anything to the screen, some of the commands I am running are forcing output that I can't seem to suppress (even with ob_start()/ob_end_clean()). For example...