views:

52

answers:

4

I've got a file index.php. there are 2 users having separate crons running accesing the scripts. is there any function in php/linux to identify which user's cron called that... its a cent-os..

A: 
  • $USER environment variable
  • whoami command
Sjoerd
nope.... the answer is apache in all cases.... since the php code is executed as apache user
Akhil K Nambiar
Please show what your cron entries look like. If you use `php -f`, this should not be the case.
Pekka
no i use CURL function... in the cron. my cron script is like */10 * * * * cron "example.com/index.php"
Akhil K Nambiar
+1  A: 

This returns the current user:

$user = exec('whoami');

http://php.net/manual/function.exec.php

slosd
nope.... the answer is apache in all cases.... since the php code is executed as apache user...
Akhil K Nambiar
+1  A: 

Two options:

  • Let the cronscript call the script directly, e.g. php -f script.php
  • Let the cronscript specifify use user as a parameter, e.g. wget http://host/script.php?user=$USER
Sjoerd
A: 

You have to pass user info from your client (cronjob in this case). On server end php process is always run by webserver (apache in your case). So setup the cron to pass user something like: example.com/index.php?user=$USER and get this on server end as $_GET['user']

Vikas