Page 1 of 1

couple of doubts regarding php & ajax.

Posted: Wed Dec 12, 2007 1:56 am
by claws
1. i noticed few times that @ (at the rate) symbol is used in php. what is this symbol. and in which context it is used?

2. why does the code inside <script> tags doesnt work if introduced using ajax. i mean
say if the response of my ajax query is
<script>alert("I Love PHP");</script>
now. using dom if i introduce this response at some node of the page. its not going to alert. why??

3. i am builing a portal in which i have a field named "validity". this is the validity period of the user's data. i mean say if validity=30 days (which is default value iam using) after thirty days that user's data will be deleted automatically. daily its value should be reduced by 1.
but how to implement this.i cant daily run a script. i want to automate this task. how to do that.
i heard of something called CRON. how to implement it?

Re: couple of doubts regarding php & ajax.

Posted: Wed Dec 12, 2007 2:07 am
by webspider
claws wrote:1. i noticed few times that @ (at the rate) symbol is used in php. what is this symbol. and in which context it is used?
@ is error suppression operator, can be used in front of any expression, that is, anything that has or generates a value.

Code: Select all

$a = @(100/0);
Without the @ operator this line will generate a divide by zero warning. With the operator included, the error is suppressed.

Re: couple of doubts regarding php & ajax.

Posted: Wed Dec 12, 2007 3:28 am
by nathanr
claws wrote:1. i noticed few times that @ (at the rate) symbol is used in php. what is this symbol. and in which context it is used?
error supression
claws wrote:2. why does the code inside <script> tags doesnt work if introduced using ajax. i mean
say if the response of my ajax query is
<script>alert("I Love PHP");</script>
now. using dom if i introduce this response at some node of the page. its not going to alert. why??
extract the scripts (using javascript) from the ajax return and add them to the head, then they'll run
claws wrote: 3. i am builing a portal in which i have a field named "validity". this is the validity period of the user's data. i mean say if validity=30 days (which is default value iam using) after thirty days that user's data will be deleted automatically. daily its value should be reduced by 1.
but how to implement this.i cant daily run a script. i want to automate this task. how to do that.
i heard of something called CRON. how to implement it?
cron = crontab, only on linux, normally found under /etc/crontab - you can edit it via vim/nano or such like - cron checks this file at regular intervals to see if there's anything it needs to run.
here's a line from mine:

Code: Select all

5  *    * * *   root    php -f /home/sites/domain.com/maildaemon.php
this runs a script called mailerdeamon via the command line every hour.

however in your case, you don't really need to decrement daily, all you need to do is know when the user signed up, then run a script every day that checks for expired users (signup date + 30 I'd presume) - and does the work. You could even add it to your index.php

if(!$clean_up_code_has_run_today) {
run_clean_up_code();
}

it means one visitor will take the weight of the clean up job, but thats only one visitor on one page call per day..

ps: why delete, why not just "deactivate"??

Posted: Wed Dec 12, 2007 2:01 pm
by aliasxneo
You don't need a cron. Just pick a moderately trafficked web page and add code that decrements the values each day. Just keep track of the last time you performed the decrement operation and check if 24 hours has passed, if so decrement them all and update the time.

Posted: Wed Dec 12, 2007 3:26 pm
by Inkyskin
That would add unnecessary code to the page that would run EVERY time it's hit - a cron is much more effective, and doesn't add more code to a page that doesn't need it. It's also a much cleaner method of running the script. It also pretty much guarantees the script runs even if that page goes down or doesn't get hit.

Posted: Wed Dec 12, 2007 5:23 pm
by aliasxneo
Inkyskin wrote:That would add unnecessary code to the page that would run EVERY time it's hit - a cron is much more effective, and doesn't add more code to a page that doesn't need it. It's also a much cleaner method of running the script. It also pretty much guarantees the script runs even if that page goes down or doesn't get hit.
Well of course a cron would be the best option, but:
i cant daily run a script
I figured that meant he didn't want to run a cron which is why I suggested the alternative. And besides, you act like such a request would really slow a page down.

Posted: Wed Dec 12, 2007 5:34 pm
by nathanr
Inkyskin wrote:That would add unnecessary code to the page that would run EVERY time it's hit
not EVERY time only ONCE.. you see you code in a check to see if the clean up codes run already in the past 24 hours or not..

again though.. why decrement. simply only allow selects to people in your db who have a subscription date within the last 30 days.. problem solved with no complicated scripts or deltions or such like.

Posted: Thu Dec 13, 2007 9:47 pm
by califdon
nathanr wrote:simply only allow selects to people in your db who have a subscription date within the last 30 days.. problem solved with no complicated scripts or deletions or such like.
Absolutely! You don't need to do anything at all until or unless the user attempts to login. When they do, check their status. Don't worry about their data remaining in the database--storage is cheap! If you get over 100 million users (you should be so lucky!) and you start worrying about disk space, you can run an admin script once a year to clean up the old records.

Posted: Thu Dec 13, 2007 10:48 pm
by crystal ship
I also suggest you to check expired date rather than cron or decrement and why don't you better disable a user rather than deleting the record of the user from the database.

Posted: Fri Dec 14, 2007 7:20 am
by claws
why don't you better disable a user rather than deleting the record of the user from the database.
yeah. i am not deleted. but just disabling.
Absolutely! You don't need to do anything at all until or unless the user attempts to login. When they do, check their status.
thats true. but this may not work in my case.
actually. their information(profiles,testimonials) are viewed publicly.
so its not "You don't need to do anything at all until or unless the user attempts to login."
so.. even the user doesnt login for say 30days or more. his profile should be automatically disabled by 30days.

yeah. i feel CRON is the better option.

Posted: Sun Dec 16, 2007 2:48 pm
by califdon
claws wrote:thats true. but this may not work in my case.
actually. their information(profiles,testimonials) are viewed publicly.
so its not "You don't need to do anything at all until or unless the user attempts to login."
so.. even the user doesnt login for say 30days or more. his profile should be automatically disabled by 30days.

yeah. i feel CRON is the better option.
I disagree. Your query that displays user information should always check for the date status. It's really very simple. Avoid making things complicated wherever possible.

Posted: Sun Dec 16, 2007 3:36 pm
by John Cartwright
califdon wrote:
claws wrote:thats true. but this may not work in my case.
actually. their information(profiles,testimonials) are viewed publicly.
so its not "You don't need to do anything at all until or unless the user attempts to login."
so.. even the user doesnt login for say 30days or more. his profile should be automatically disabled by 30days.

yeah. i feel CRON is the better option.
I disagree. Your query that displays user information should always check for the date status. It's really very simple. Avoid making things complicated wherever possible.
In this case I would agree with califdon. If you are storing the last login date as a mysql timestamp then it is a simple WHERE clause to determine who is valid or not. No need for a separate cron daemon to do extremely simple processing.

Re: couple of doubts regarding php & ajax.

Posted: Mon Dec 17, 2007 3:53 am
by CoderGoblin
claws wrote:1. i noticed few times that @ (at the rate) symbol is used in php. what is this symbol. and in which context it is used?
As has already been noted this is used for error suppression but should be used with caution. Hiding errors is not a good solution, Defensive coding is. If you are not careful lack of error messages may produce annoyingly hard to trace errors elsewhere in your code.

Posted: Mon Dec 17, 2007 8:50 am
by chakhar86
equal to crontab on linux.... use "at" in windows

Posted: Mon Dec 17, 2007 9:33 am
by feyd
icron is a cron analogue on Windows. "at" is not as direct of an analogue.